#include <bits/stdc++.h>
using namespace std;
int R, C;
char a[105][105];
bool visited[105][105];
int xi[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int yj[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
void dfs(int x, int y) {
  if (x < 0 || y < 0 || x >= R || y >= C) {
    return;
  }
  if (a[x][y] == '.' || visited[x][y] == true) return;
  visited[x][y] = true;
  for (int i = 0; i < 8; i++) {
    dfs(x + xi[i], y + yj[i]);
  }
}
int main() {
  while (~scanf("%d%d", &R, &C)) {
    getchar();
    memset(visited, false, sizeof(visited));
    for (int i = 0; i < R; i++) {
      for (int j = 0; j < C; j++) {
        a[i][j] = getchar();
      }
      getchar();
    }
    int cnt = 0;
    for (int i = 0; i < R; i++) {
      for (int j = 0; j < C; j++) {
        if (a[i][j] == 'B' && !visited[i][j]) {
          dfs(i, j);
          cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
