#include <bits/stdc++.h>
using namespace std;
int dx[] = {+0, +1, +0, -1};
int dy[] = {+1, +0, -1, +0};
int r, c, uu, vv, ans;
char board[100][100];
void dfs(int u, int v) {
  board[u][v] = '.';
  for (int k = 0; k < 4; k++) {
    uu = u + dx[k];
    vv = v + dy[k];
    if (uu >= 0 and vv >= 0 and uu < r and vv < c and board[uu][vv] == 'B')
      dfs(uu, vv);
  }
}
int main() {
  int i, j;
  scanf("%d%d", &r, &c);
  for (i = 0; i < r; i++) scanf("%s", board[i]);
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      if (board[i][j] == 'B') {
        ++ans;
        dfs(i, j);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
