#include <bits/stdc++.h>
using namespace std;
const int MAX = 21234;
const int MAXT = 1123456;
const int P = 1000000007;
const int INF = 11234567;
const double EPS = 1e-6;
const double PI = 3.14159265358979;
int main(void) {
  int r, c, total = 0;
  char ant, atual;
  scanf("%d %d", &r, &c);
  for (int i = 0; i < r; i++) {
    getchar();
    for (int j = 0; j < c; j++) {
      scanf("%c", &atual);
      if (i == r - 1) {
        if (j) {
          if (ant == '.' && atual == 'B') total++;
        } else {
          if (atual == 'B') total++;
        }
        ant = atual;
      }
    }
  }
  printf("%d\n", total);
  return 0;
}
