#include <bits/stdc++.h>
int main() {
  char arr[101][101];
  int a, b, x, y, check = 0;
  scanf("%d%d\n", &a, &b);
  for (x = 0; x < a; x++) {
    gets(arr[x]);
  }
  for (y = 0; y < b; y++) {
    if (arr[a - 1][y] == 'B') {
      if (arr[a - 1][y + 1] == '.')
        check++;
      else {
        if (y == b - 1 && arr[a - 1][y] == 'B') check++;
      }
    }
  }
  printf("%d", check);
}
