#include <bits/stdc++.h>
using namespace std;
int tu[102][102], ans = 0, n, m, vis[102][102], bx[5], by[5];
void dfs(int x, int y) {
  vis[x][y] = 1;
  for (int k = 1; k <= 4; k++) {
    int i = x + bx[k], j = y + by[k];
    if (tu[i][j] && vis[i][j] == 0) dfs(i, j);
  }
}
int main() {
  cin >> n >> m;
  char a;
  bx[1] = 1, bx[2] = 0, bx[3] = -1, bx[4] = 0;
  by[1] = 0, by[2] = 1, by[3] = 0, by[4] = -1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> a;
      if (a == 'B')
        tu[i][j] = 1;
      else
        tu[i][j] = 0;
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (!vis[i][j] && tu[i][j]) dfs(i, j), ans++;
  printf("%d", ans);
  return 0;
}
