#include <bits/stdc++.h>
using namespace std;
char graph[507][507];
int gra[507][507];
int n, m;
void dfs(int i, int j) {
  if (graph[i - 1][j] == 'B') {
    graph[i - 1][j] = '.';
    dfs(i - 1, j);
  }
  if (graph[i + 1][j] == 'B') {
    graph[i + 1][j] = '.';
    dfs(i + 1, j);
  }
  if (graph[i][j - 1] == 'B') {
    graph[i][j - 1] = '.';
    dfs(i, j - 1);
  }
  if (graph[i][j + 1] == 'B') {
    graph[i][j + 1] = '.';
    dfs(i, j + 1);
  }
}
int main() {
  int cnt = 0;
  cin >> n >> m;
  for (int i = 0; i <= n + 1; i++) {
    graph[i][0] = '.';
    graph[i][m + 1] = '.';
  }
  for (int i = 0; i <= m + 1; i++) {
    graph[0][i] = '.';
    graph[n + 1][i] = '.';
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> graph[i][j];
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (graph[i][j] == 'B') {
        graph[i][j] = '.';
        dfs(i, j);
        cnt++;
      }
    }
  cout << cnt << endl;
  return 0;
}
