#include <bits/stdc++.h>
using namespace std;
const int N = 112;
bool used[N][N];
char a[N][N];
int dx[] = {1, 0, 0, -1};
int dy[] = {0, 1, -1, 0};
int n, m;
void dfs(int x, int y) {
  used[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    int xx = x + dx[i];
    int yy = y + dy[i];
    if (xx >= 1 && xx <= n && yy >= 1 && yy <= m && a[xx][yy] == 'B' &&
        used[xx][yy] == 0)
      dfs(xx, yy);
  }
}
int main() {
  int i, j, x, y;
  cin >> n >> m;
  int cnt = 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> a[i][j];
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      if (a[i][j] == 'B' && used[i][j] == 0) dfs(i, j), cnt++;
  cout << cnt;
}
