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