#include <bits/stdc++.h>
int main(void) {
  int R, C, i, j, num;
  char str[100][100];
  while (scanf("%d%d", &R, &C) != EOF) {
    getchar();
    for (i = 0; i < R; i++) {
      for (j = 0; j < C; j++) {
        scanf("%c", &str[i][j]);
      }
      getchar();
    }
    num = 0;
    if (str[R - 1][0] == 'B') num++;
    for (j = 1; j < C; j++) {
      if (str[R - 1][j - 1] == '.' && str[R - 1][j] == 'B')
        num++;
      else if (str[R - 1][j - 1] == 'B' && str[R - 1][j] == 'B')
        continue;
    }
    printf("%d\n", num);
  }
  return 0;
}
