#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 5;
const int dr[] = {1, -1, 0, 0};
const int dc[] = {0, 0, 1, -1};
char a[maxn][maxn];
int vis[maxn][maxn];
void dfs(int r, int c) {
  vis[r][c] = 1;
  for (int i = 0; i < 4; ++i) {
    int x = r + dr[i];
    int y = c + dc[i];
    if (!vis[x][y] && a[x][y] == 'B') dfs(x, y);
  }
}
int main() {
  int r, c;
  cin >> r >> c;
  getchar();
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < r; ++i) cin >> a[i];
  int ans = 0;
  for (int i = 0; i < r; ++i)
    for (int j = 0; j < c; ++j)
      if (a[i][j] == 'B' && !vis[i][j]) {
        ++ans;
        dfs(i, j);
      }
  cout << ans << endl;
  return 0;
}
