#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e3 + 10;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int n, m, was[MaxN][MaxN];
char s[MaxN][MaxN];
void push(int x, int y) {
  if (s[x][y] != 'B') return;
  if (was[x][y]) return;
  was[x][y] = 1;
  push(x - 1, y);
  push(x + 1, y);
  push(x, y - 1);
  push(x, y + 1);
}
int main() {
  scanf("%d%d\n", &n, &m);
  for (int i = 1; i <= n; ++i) {
    gets(s[i] + 1);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (s[i][j] == 'B' && !was[i][j]) {
        push(i, j);
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
