#include <bits/stdc++.h>
using namespace std;
int n, m, ans, px[4], py[4];
bool a[200][200], usd[200][200];
char h;
void dfs(int x, int y) {
  if (x < 0 || x >= n || y < 0 || y >= m || usd[x][y]) return;
  usd[x][y] = 1;
  for (int i = 0; i < 4; ++i) {
    int nx = x + px[i];
    int ny = y + py[i];
    if (nx < 0 || nx >= n || ny < 0 || ny >= m || usd[nx][ny] || !a[nx][ny])
      continue;
    dfs(nx, ny);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      cin >> h;
      if (h == 'B') a[i][j] = 1;
    }
  px[0] = 0;
  py[0] = 1;
  px[1] = 0;
  py[1] = -1;
  px[2] = 1;
  py[2] = 0;
  px[3] = -1;
  py[3] = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (!usd[i][j] && a[i][j]) {
        ans++;
        dfs(i, j);
      }
  cout << ans;
}
