#include <bits/stdc++.h>
using std::queue;
struct node {
  int x, y;
};
const int maxn = 100 + 5;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
char M[maxn][maxn];
bool vis[maxn][maxn];
queue<node> q;
int main(int argc, char **argv) {
  int r, c, i, j, x, y, k, sum = 0;
  node tmp;
  scanf("%d%d", &r, &c);
  for (i = 0; i < r; i++) scanf("%s", M[i]);
  memset(vis, 0, sizeof(vis));
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      if (vis[i][j] || M[i][j] == '.') continue;
      q.push((node){i, j});
      while (!q.empty()) {
        tmp = q.front();
        q.pop();
        for (k = 0; k < 4; k++) {
          x = tmp.x + dx[k];
          y = tmp.y + dy[k];
          if (x >= 0 && y >= 0 && x < r && y < c)
            if (!vis[x][y] && M[x][y] == 'B') {
              q.push((node){x, y});
              vis[x][y] = 1;
            }
        }
      }
      sum++;
    }
  }
  printf("%d\n", sum);
  return 0;
}
