#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
using namespace std;
const long long INF = 1e9;
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<string> smth(n);
  for (long long i = 0; i < n; i++) {
    cin >> smth[i];
  }
  long long cnt = 0;
  for (long long i = 0; i < m; i++) {
    if (smth[n - 1][i] == 'B' && (i == m - 1 || smth[n - 1][i + 1] == '.'))
      cnt++;
  }
  cout << cnt << endl;
}
