#include <bits/stdc++.h>
using namespace std;
int r, c;
int cc = 0;
char grid[105][105];
bool vis[105][105];
void dfs(int x, int y) {
  if (x < 0 || y < 0 || x >= r || y >= c) return;
  if (vis[x][y] || grid[x][y] == '.') return;
  vis[x][y] = 1;
  dfs(x + 1, y);
  dfs(x, y + 1);
  dfs(x - 1, y);
  dfs(x, y - 1);
}
int main() {
  cin >> r >> c;
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++) cin >> grid[i][j];
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++)
      if (!vis[i][j] && grid[i][j] == 'B') {
        cc++;
        dfs(i, j);
      }
  cout << cc << "\n";
}
