#include <bits/stdc++.h>
static const int MAX_SIZE = 100;
char buffer[MAX_SIZE + 10];
const char BRICK = 'B';
const char HOLE = '.';
int main() {
  int rows, cols;
  scanf("%d %d\n", &rows, &cols);
  int rowsCounter = 0;
  for (int i = 0; i < rows; i++) {
    fgets(buffer, sizeof(buffer), stdin);
  }
  bool IsWall = false;
  int partsNumber = 0;
  for (int i = 0; i < cols; i++) {
    if (buffer[i] == BRICK) {
      if (IsWall == false) {
        IsWall = true;
        partsNumber++;
      }
    } else {
      IsWall = false;
    }
  }
  printf("%d", partsNumber);
  return 0;
}
