#include<bits/stdc++.h>
using namespace std;
int n, m;
char str[110][110];
int cnt;
int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
void dfs(int x, int y) {
str[x][y] = '.';
for (int i = 0; i < 8; i++) {
int tx = dx[i] + x;
int ty = dy[i] + y;
if (tx >= 1 && ty >= 1 && tx <= n && ty <= m && str[tx][ty] == 'W') {
dfs(tx, ty);
}
}
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> str[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (str[i][j] == 'W') {
cnt++;
dfs(i, j);
}
}
}
cout << cnt;
return 0;
}