#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
template <class T>
bool scanff(T &ret) {
  char c;
  int sgn;
  T bit = 0.1;
  if (c = getchar(), c == EOF) return 0;
  while (c != '-' && c != '.' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  if (c == ' ' || c == '\n') {
    ret *= sgn;
    return 1;
  }
  while (c = getchar(), c >= '0' && c <= '9') ret += (c - '0') * bit, bit /= 10;
  ret *= sgn;
  return 1;
}
using namespace std;
char s[111][111];
int vis[111][111];
int n, m, ans = 0;
int dx[4] = {0, -1, 1, 0};
int dy[4] = {1, 0, 0, -1};
void dfs(int x, int y) {
  if (vis[x][y]) return;
  if (s[x][y] == '.') return;
  if (x < 1 || x > n || y < 1 || y > m) return;
  vis[x][y] = 1;
  for (int i = int(0); i <= int(3); i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    dfs(nx, ny);
  }
}
int main() {
  scanff(n);
  scanff(m);
  for (int i = int(1); i <= int(n); i++) scanf("%s", s[i] + 1);
  for (int i = int(1); i <= int(n); i++)
    for (int j = int(1); j <= int(m); j++) {
      if (s[i][j] == 'B' && !vis[i][j]) {
        ans++;
        dfs(i, j);
      }
    }
  printf("%d\n", ans);
  return 0;
}
