#include <bits/stdc++.h>
char a[105][105];
int direct[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int mark[105][105];
void dfs(int x, int y) {
  int dx, dy;
  for (int i = 0; i < 4; i++) {
    dx = x + direct[i][0];
    dy = y + direct[i][1];
    if (mark[dx][dy] == 0 && a[dx][dy] == 'B') {
      mark[dx][dy] = 1;
      dfs(dx, dy);
    }
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", a[i] + 1);
  memset(mark, 0, sizeof(mark));
  int k = 1;
  int sum = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (mark[i][j] == 0 && a[i][j] == 'B') {
        sum++;
        mark[i][j] = 1;
        dfs(i, j);
      }
  printf("%d\n", sum);
}
