#include <bits/stdc++.h>
using namespace std;
int M, N, ans;
string str[200];
void dfs(int m, int n) {
  str[m][n] = '.';
  if (m + 1 <= M && str[m + 1][n] == 'B') dfs(m + 1, n);
  if (m - 1 >= 0 && str[m - 1][n] == 'B') dfs(m - 1, n);
  if (n + 1 <= N && str[m][n + 1] == 'B') dfs(m, n + 1);
  if (n - 1 >= 0 && str[m][n - 1] == 'B') dfs(m, n - 1);
}
int main() {
  cin >> M >> N;
  getchar();
  for (int i = 0; i < M; i++) getline(cin, str[i]);
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < N; j++) {
      if (str[i][j] == 'B') {
        dfs(i, j);
        ans++;
      }
    }
  }
  cout << ans << endl;
}
