#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  char a[n][m];
  string s;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  for (int k = 0; k < m; ++k) {
    if (a[n - 1][k] == 'B')
      s += '1';
    else
      s += '0';
  }
  s.erase(unique(s.begin(), s.end()), s.end());
  int term = 0;
  for (auto p : s) {
    if (p == '1') term++;
  }
  cout << term;
  return 0;
}
