#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  int f = 0, c = 0;
  int x = 0;
  cin >> n >> m;
  char a[n][m];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < m; i++) {
    f = 0;
    for (int j = 0; j < n; j++) {
      if (a[j][i] == 'B') {
        f = 1;
        break;
      }
    }
    if (f == 0 && x == 1) c++;
    x = f;
  }
  if (f == 1) c++;
  cout << c;
}
