#include <bits/stdc++.h>
using namespace std;
const int MN = 100011;
const int inf = 1e9 + 7;
int n, m;
char c[1000][1000];
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = (1), _b = (n); i <= _b; ++i)
    for (int j = (1), _b = (m); j <= _b; ++j) cin >> c[i][j];
  long long res = 0, ok = 0;
  for (int i = (1), _b = (m); i <= _b; ++i) {
    if (c[n][i] == 'B') {
      if (!ok) res++;
      ok = 1;
    } else
      ok = 0;
  }
  cout << res;
  return 0;
}
