#include <bits/stdc++.h>
using namespace std;
int a[1001], x, y;
char s[110][110];
int bingchaji(int n) {
  if (a[n] == n) return n;
  a[n] = bingchaji(a[n]);
  return a[n];
}
void oo(int n, int m) {
  if (n < 0 || m < 0 || n > x || m > y) return;
  if (s[n][m] == 'B')
    s[n][m] = '.';
  else
    return;
  oo(n - 1, m);
  oo(n + 1, m);
  oo(n, m - 1);
  oo(n, m + 1);
}
int main() {
  int n, i, j, k, l, m, t = 0;
  cin >> n >> m;
  x = n - 1;
  y = m - 1;
  for (i = 0; i < n; i++) cin >> s[i];
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      if (s[i][j] == 'B') {
        t++;
        oo(i, j);
      }
  cout << t << endl;
}
