#include <bits/stdc++.h>
using namespace std;
char grid[110][110];
int dir[4][2] = {(1, 0), (-1, 0), (0, 1), (0, -1)};
int sum = 0, r, c;
void dfs(int x, int y) {
  for (int i = 0; i < 4; i++) {
    int dx = x + dir[0][i];
    int dy = y + dir[1][i];
    if (dx >= 0 && dx < r && dy >= 0 && dy < c) {
      if (grid[dx][dy] == 'B') {
        grid[dx][dy] = '.';
        dfs(dx, dy);
      }
    }
  }
}
int main() {
  scanf("%d %d", &r, &c);
  for (int i = 0; i < r; i++) {
    scanf("%s", &grid[i]);
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      if (grid[i][j] == 'B') {
        sum++;
        dfs(i, j);
        grid[i][j] = '.';
      }
    }
  }
  printf("%d\n", sum);
  return 0;
}
