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