#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[1005][1005];
bool vis[1005][1005];
int xx[4] = {1, -1, 0, 0};
int yy[4] = {0, 0, 1, -1};
void dfs(int i, int j) {
  if (i < 0 || i >= n || j < 0 || j >= m) return;
  if (vis[i][j]) return;
  if (a[i][j] != 'B') return;
  vis[i][j] = 1;
  for (int k = 0; k < 4; k++) {
    dfs(i + xx[k], j + yy[k]);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (a[i][j] != 'B') continue;
      if (vis[i][j]) continue;
      dfs(i, j);
      ans++;
    }
  cout << ans << "\n";
  return 0;
}
