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