#include <bits/stdc++.h>
using namespace std;
void solve(int test_number);
void pre() {
  cout.setf(ios::fixed);
  cout.precision(20);
  cerr.setf(ios::fixed);
  cerr.precision(3);
}
void post() {
  fprintf(stderr, "\n");
  fprintf(stderr, "Execution time: %Lf", (long double)clock());
}
const int MAXN = 100100;
inline void solve(int test_number) {
  int n, m;
  string s;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    cin >> s;
  }
  int ans = 0, curAns = 0;
  for (int i = 0; i < ((int)(s).size()); i++) {
    if (s[i] == 'B') {
      curAns++;
    } else {
      if (curAns != 0) ans++, curAns = 0;
    }
  }
  printf("%d", ans + (curAns != 0 ? 1 : 0));
  return;
}
int main() {
  pre();
  int n = 1;
  for (int i = 0; i < n; i++) {
    solve(i + 1);
  }
  post();
  return 0;
}
