#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const long double PI = acosl((long double)-1.0);
const long long LINF = 1e18;
const int MOD = 1000000007;
const int MAXN = 105;
int n, m;
char f[MAXN][MAXN];
int used[MAXN][MAXN];
int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};
void init() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", &f[i][1]);
  }
}
inline bool valid(int x, int y) { return 1 <= x && x <= n && 1 <= y && y <= m; }
void dfs(int x, int y) {
  used[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    if (valid(x + dx[i], y + dy[i]) && f[x + dx[i]][y + dy[i]] == 'B' &&
        !used[x + dx[i]][y + dy[i]]) {
      dfs(x + dx[i], y + dy[i]);
    }
  }
}
void solve() {
  init();
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (f[i][j] == 'B' && !used[i][j]) {
        dfs(i, j);
        ans++;
      }
    }
  }
  printf("%d\n", ans);
}
void precalc() {}
int main() {
  srand(25);
  precalc();
  int tests = 1;
  for (int i = 1; i <= tests; i++) {
    solve();
  }
  return 0;
}
