#include <bits/stdc++.h>
using namespace std;
int N, M, t;
int mp[101][101];
int color[101][101];
bool v[101][101];
char c;
int dx[8] = {1,1,0,-1,-1,-1,0,1};
int dy[8] = {0,1,1,1,0,-1,-1,-1};
void dfs(int x, int y){
if(!mp[x][y] || color[x][y] || v[x][y]) return;
color[x][y] = t;
for(int i=0; i<8; i++){
v[x][y] = true;
dfs(x+dx[i], y+dy[i]);
v[x][y] = false;
}
}
int main(){
scanf("%d %d", &N, &M);
for(int i=1; i<=N; i++){
for(int j=1; j<=M; j++){
c = getchar();
if(c == 'W') mp[i][j] = 1;
}
getchar();
}
for(int i=1; i<=N; i++){
for(int j=1; j<=M; j++){
if(mp[i][j] && !color[i][j]){
t++;
dfs(i, j);
}
}
}
printf("%d\n", t);
return 0;
}