#include <bits/stdc++.h>
using namespace std;
int n, m;
char g[1005][1005];
int vis[1005][1005];
int cnt;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, -1, 1};
bool inside(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; }
void dfs(int x, int y) {
  if (vis[x][y] || x < 1 || y < 1 || x > n || y > m) return;
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++)
    if (g[x + dx[i]][y + dy[i]] == 'B') dfs(x + dx[i], y + dy[i]);
}
int main() {
  memset(vis, 0, sizeof(vis));
  cnt = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", &g[i][1]);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (!vis[i][j] && g[i][j] == 'B') {
        cnt++;
        dfs(i, j);
      }
    }
  }
  printf("%d\n", cnt);
  return 0;
}
