#include <bits/stdc++.h>
using namespace std;
int main() {
  int r, c;
  scanf("%d %d", &r, &c);
  char tb[c + 1];
  for (int i = 0; i < r; i++) scanf("%s", tb);
  r = 0;
  for (int i = 0; i < c; i++)
    if (tb[i] == '.' && i > 0 && tb[i - 1] == 'B') {
      r++;
    }
  if (tb[c - 1] == 'B') r++;
  printf("%d", r);
  return 0;
}
