#include <bits/stdc++.h>
using namespace std;
int main() {
  int wall[110][110] = {0};
  int r, c;
  scanf("%d %d%*c", &r, &c);
  char a[110];
  for (int i = 1; i < r; i++) gets(a);
  int flag = 0;
  int seg = 0;
  for (int i = 0; i < c; i++) {
    char x;
    scanf("%c", &x);
    if (flag == 0) {
      if (x == 'B') {
        flag++;
        seg++;
      } else
        continue;
    } else {
      if (x == 'B')
        continue;
      else
        flag = 0;
    }
  }
  printf("%d\n", seg);
}
