#include <bits/stdc++.h>
struct {
  int v, nxt;
} e[1005 << 1];
int n, adj[1005], c, m, vis[1005];
inline void Add(int u, int v) {
  e[++c].v = v;
  e[c].nxt = adj[u];
  adj[u] = c;
}
void dfs(int u) {
  vis[u] = 1;
  for (int i = adj[u]; i; i = e[i].nxt)
    if (!vis[e[i].v]) {
      dfs(e[i].v);
    }
}
char s[1005];
int main() {
  scanf("%d%d", &n, &m);
  int u, v;
  for (int i = 1; i <= n; ++i) scanf("%s", s + 1);
  bool b = 0;
  int ans = 0;
  for (int i = 1; i <= m; ++i) {
    if (s[i] == 'B') {
      if (!b) ++ans;
      b = 1;
    } else {
      b = 0;
    }
  }
  printf("%d\n", ans);
  return 0;
}
