#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
char a[110];
int main() {
  cin >> n >> m;
  for (int i = 1; i < n; i++)
    for (int j = 1; j <= m; j++) {
      char ch;
      cin >> ch;
    }
  for (int j = 1; j <= m; j++) cin >> a[j];
  for (int i = 1; i <= m; i++)
    if (a[i] == 'B') {
      ans++;
      while (i + 1 <= m && a[i + 1] == 'B') i++;
    }
  cout << ans << endl;
  return 0;
}
