#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  char prev = '.';
  int ans = 0;
  char c;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> c;
      if (i != n - 1) continue;
      if (j == 0) {
        prev = c;
        continue;
      }
      if (c == '.' and prev == 'B') ans++;
      prev = c;
    }
  }
  if (c == 'B') ans++;
  cout << ans << "\n";
  return 0;
}
