#include <bits/stdc++.h>
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
char str[1010][1010];
int n, m, res, visited[1010][1010];
void dfs(int i, int j) {
  int d, k, l;
  visited[i][j] = 1;
  for (d = 0; d < 4; d++) {
    k = i + dx[d], l = j + dy[d];
    if (((k) >= 0 && (k) < n && (l) >= 0 && (l) < m) && !visited[k][l] &&
        str[k][l] == 'B')
      dfs(k, l);
  }
}
int main() {
  int i, j, k, l;
  while (scanf("%d %d", &n, &m) != EOF) {
    res = 0;
    memset(visited, 0, sizeof(visited));
    for (i = 0; i < n; i++) scanf("%s", str[i]);
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (str[i][j] == 'B' && !visited[i][j]) {
          res++;
          dfs(i, j);
        }
      }
    }
    printf("%d\n", res);
  }
  return 0;
}
