#include <bits/stdc++.h>
using namespace std;
const int N = 110, INF = (int)1e9, mod = (int)1e9 + 7;
int cnt, n, m;
char a[N][N];
const int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
void dfs(int x, int y) {
  a[x][y] = '.';
  for (int i = (int)(0); i <= (int)(3); i++) {
    int X = x + dx[i], Y = y + dy[i];
    if (X < 1 || X > n || Y < 1 || Y > m || a[X][Y] == '.') continue;
    dfs(X, Y);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(1); j <= (int)(m); j++) cin >> a[i][j];
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(1); j <= (int)(m); j++)
      if (a[i][j] == 'B') {
        dfs(i, j);
        cnt++;
      }
  cout << cnt << endl;
}
