#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n, m;
char s[N][N];
bool vis[N][N];
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
void dfs(int x, int y) {
  vis[x][y] = 1;
  for (int i = 0; i < 4; ++i) {
    int nx = x + dx[i], ny = y + dy[i];
    if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
      if (!vis[nx][ny] && s[nx][ny] == 'B') dfs(nx, ny);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", s[i]);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == 'B' && !vis[i][j]) ++ans, dfs(i, j);
    }
  }
  printf("%d\n", ans);
  return 0;
}
