#include <bits/stdc++.h>
using namespace std;
int R, C;
char A[200][200];
bool vis[200][200];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
void DFS(int x, int y) {
  if (x >= R || x < 0 || y >= C || y < 0 || A[x][y] == '.' || vis[x][y]) return;
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    DFS(x + dx[i], y + dy[i]);
  }
}
int main() {
  int cnt = 0;
  scanf("%d%d", &R, &C);
  for (int i = 0; i < R; i++) cin >> A[i];
  for (int i = 0; i < R; i++) {
    for (int j = 0; j < C; j++) {
      if (!vis[i][j] && A[i][j] == 'B') DFS(i, j), cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
