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