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