#include <bits/stdc++.h>
using namespace std;
char a[101][101];
int n, m, k = 0;
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int used[101][101];
void dfs(int start_x, int start_y) {
  used[start_x][start_y] = k;
  for (int i = 0; i < 4; i++) {
    int to_x = start_x + dx[i], to_y = start_y + dy[i];
    if (to_x > 0 && to_x <= n && to_y > 0 && to_y <= m &&
        a[to_x][to_y] == 'B' && used[to_x][to_y] == 0)
      dfs(to_x, to_y);
  }
}
int main() {
  int i, j;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    getchar();
    for (j = 1; j <= m; j++) a[i][j] = getchar();
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      if (a[i][j] == 'B' && used[i][j] == 0) {
        k++;
        dfs(i, j);
      }
  cout << k << endl;
  return 0;
}
