#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int m, n;
bool flag[N][N];
void fs(int x, int y) {
  if (flag[x][y] == false) return;
  flag[x][y] = false;
  fs(x, y - 1);
  fs(x - 1, y);
  fs(x + 1, y);
  fs(x, y + 1);
}
int execute() {
  int res = 0;
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (flag[i][j]) {
        res += 1;
        fs(i, j);
      }
    }
  }
  return res;
}
int main() {
  while (cin >> m >> n) {
    memset(flag, 0, sizeof(flag));
    char c[N];
    for (int i = 0; i < m; ++i) {
      cin >> c;
      for (int j = 0; j < n; ++j) {
        char t = c[j];
        if (t == 'B') {
          flag[i + 1][j + 1] = true;
        }
      }
    }
    cout << execute() << endl;
  }
  return 0;
}
