#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int r, c, i, j, cnt = 0, ans = 0;
  cin >> r >> c;
  char x, arr[c];
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> x;
      if (i == r - 1) arr[j] = x;
    }
  }
  for (j = 0; j < c;) {
    if (arr[j] == 'B') {
      while (arr[j++] == 'B' and j < c) continue;
      ans++;
    } else
      j++;
  }
  cout << ans << endl;
  return 0;
}
