#include <bits/stdc++.h>
using namespace std;
char x[2000][2000];
set<char> s;
long long n, m, ans = 0;
char k = '1';
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n; ++i)
    for (long long j = 0; j < m; ++j) {
      cin >> x[i][j];
    }
  for (long long i = 0; i < m; ++i)
    if (x[n - 1][i] == 'B' && (x[n - 1][i + 1] == '.' || i == m - 1)) ans++;
  cout << ans;
  return 0;
}
