#include <bits/stdc++.h>
using namespace std;
int qq, n, m, k, l, r;
string s, s1, s2, s3;
int INF = (int)2e9 + 7;
struct st {
  int x, y;
};
bool operator<(st& a, st& b) {
  if (a.x != b.x) return a.x < b.x;
  return a.y < b.y;
}
vector<vector<char>> v;
int x[4] = {0, 0, -1, 1}, y[4] = {-1, 1, 0, 0};
void dfs(int i, int j) {
  v[i][j] = '.';
  for (int ii = 0; ii < 4; ii++) {
    if (v[i + x[ii]][j + y[ii]] == 'B') dfs(i + x[ii], j + y[ii]);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k1, k2, c;
  char e;
  cin >> n >> m;
  int ans = 0;
  v.assign(n + 2, vector<char>(m + 2));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> e;
      v[i][j] = e;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (v[i][j] == 'B') {
        dfs(i, j);
        ans++;
      }
    }
  }
  cout << ans << " ";
  cin >> k;
  return 0;
}
