#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<char>> grid(n, vector<char>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      char ch;
      cin >> ch;
      grid[i][j] = ch;
    }
  }
  int res = 0;
  for (int i = 0, j = 0; i < m;) {
    for (; j < m && grid[n - 1][j] != 'B'; ++j)
      ;
    if (j < m) {
      for (; j < m && grid[n - 1][j] == 'B'; ++j)
        ;
      res++;
      i = j;
      continue;
    }
    i = j + 1;
  }
  cout << res << "\n";
}
