#include <bits/stdc++.h>
using namespace std;
int main() {
  long i, j, R, C;
  cin >> R >> C;
  char adj[R][C];
  for (i = 0; i < R; i++) {
    for (j = 0; j < C; j++) {
      cin >> adj[i][j];
    }
  }
  i = R - 1;
  long ans = 0;
  j = 0;
  while (j < C) {
    if (adj[i][j] == '.') {
      j++;
      continue;
    }
    ans++;
    while (j < C && adj[i][j] == 'B') j++;
  }
  cout << ans;
  return 0;
}
