#include <bits/stdc++.h>
using namespace std;
int main() {
  int r, c, i, j;
  cin >> r >> c;
  char a[r][c];
  int k = 0;
  int q = 0;
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> a[i][j];
      if (i == r - 1) {
        if (a[i][j] == 'B') {
          q = 1;
          if (j == c - 1) {
            k++;
          }
        } else if (a[i][j] == '.') {
          if (q == 1) {
            k++;
          }
          q = 0;
        }
      }
    }
  }
  cout << k;
}
