#include <bits/stdc++.h>
using namespace std;
int R, C;
char S[102][102];
int visit[102][102];
void dfs(int i, int j) {
  if (i < 0 || j < 0 || i >= R || j >= C) return;
  if (visit[i][j] || S[i][j] == '.') return;
  visit[i][j] = 1;
  dfs(i + 1, j);
  dfs(i - 1, j);
  dfs(i, j + 1);
  dfs(i, j - 1);
}
int main() {
  scanf("%d %d", &R, &C);
  for (int i = 0; i < R; i++) scanf(" %s", S[i]);
  int ans = 0;
  for (int i = 0; i < R; i++)
    for (int j = 0; j < C; j++)
      if (S[i][j] == 'B' && !visit[i][j]) {
        ans++;
        dfs(i, j);
      }
  printf("%d\n", ans);
  return 0;
}
