#include <iostream>
using namespace std;
int N, M;
const int MAX_N = 1000;
const int MAX_M = 1000;
char field[MAX_N][MAX_M + 1];
int dfs(int x, int y)//现在位置(x,y);
{
field[x][y] = '.';//将现在所在位置替换成‘.’;
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
int nx = x + dx, ny = y + dy;
//向x方向移动dx,向y方向移动dy,移动的结果为(nx,ny);
if (0 <= nx&&nx < N && 0 <= ny&&ny < M&&field[nx][ny] == 'w')
dfs(nx,ny);
//判断(nx,ny)是不是在院子内,以及是否有积水;
}
}
return 1;
}
void solve()
{
int res = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (field[i][j] == 'w') {
dfs(i, j);
res++;
//从有'w'的地方开始dfs;
}
}
}
cout << res << endl;
}
int main()
{
cin >> N >> M;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cin >> field[i][j];//输入图形;
}
}
solve();
system("pause");
return 0;
}