#include <bits/stdc++.h>
using namespace std;
char a[105];
int main() {
  int n, m, i, j, k, b;
  int ans = 0;
  cin >> n >> m;
  for (i = 0; i < n; ++i)
    for (j = 0; j < m; ++j) cin >> a[j];
  for (i = 0; i < m; ++i) {
    if (a[i] == 'B') {
      if (i == 0 || a[i - 1] != 'B') ans++;
    }
  }
  cout << ans;
}
