#include <bits/stdc++.h>
using namespace std;
long long dx[] = {1, 0, -1, 0};
long long dy[] = {0, 1, 0, -1};
char grid[101][101];
bool vis[101][101];
long long concomp = 0;
void floodfill(long long x, long long y) {
  for (long long i = 0; i < 4; i++) {
    if (!vis[x + dx[i]][y + dy[i]] && grid[x + dx[i]][y + dy[i]] == 'B') {
      vis[x + dx[i]][y + dy[i]] = true;
      floodfill(x + dx[i], y + dy[i]);
    }
  }
}
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long x = 0; x < n; x++) {
    for (long long y = 0; y < m; y++) {
      cin >> grid[x][y];
    }
  }
  for (long long x = 0; x < n; x++) {
    for (long long y = 0; y < m; y++) {
      if (!vis[x][y] && grid[x][y] == 'B') {
        vis[x][y] = true;
        floodfill(x, y);
        concomp++;
      }
    }
  }
  cout << concomp << endl;
  return 0;
}
