#include <bits/stdc++.h>
using namespace std;
char a[1000][1000];
int res, n, m, dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
void doc() {
  cin >> n >> m;
  int i, j;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> a[i][j];
}
void dequy(int i, int j) {
  a[i][j] = '.';
  int u, v;
  for (int k = 0; k < 4; k++) {
    u = i + dx[k];
    v = j + dy[k];
    if (a[u][v] == 'B') dequy(u, v);
  }
}
void solve() {
  int i, j;
  res = 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      if (a[i][j] == 'B') {
        res++;
        dequy(i, j);
      }
}
void xuat() { cout << res; }
int main() {
  doc();
  solve();
  xuat();
}
