#include <bits/stdc++.h>
using namespace std;
const int MAX_H = 100;
const int MAX_W = 100;
char s[MAX_W + 4];
int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  for (int y = 0; y < h; y++) scanf("%s", s);
  int c = 0;
  for (int i = 0; i < w;) {
    while (i < w && s[i] == '.') i++;
    if (i >= w) break;
    while (i < w && s[i] == 'B') i++;
    c++;
  }
  printf("%d\n", c);
  return 0;
}
