#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T& num) {
  char CH;
  bool F = false;
  for (CH = getchar(); CH < '0' || CH > '9'; F = CH == '-', CH = getchar())
    ;
  for (num = 0; CH >= '0' && CH <= '9';
       num = num * 10 + CH - '0', CH = getchar())
    ;
  F && (num = -num);
}
int stk[70], tp;
template <class T>
inline void print(T p) {
  if (!p) {
    puts("0");
    return;
  }
  while (p) stk[++tp] = p % 10, p /= 10;
  while (tp) putchar(stk[tp--] + '0');
  putchar('\n');
}
const long long mod = 1e9 + 7;
const double PI = acos(-1.0);
const long long inf = 1e18;
const int N = 2e5 + 10;
const int maxn = 1005;
const double eps = 1e-10;
int n, m, vis[104][104], dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1};
char mp[104][104];
void dfs(int x, int y) {
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    int fx = x + dir[i][0], fy = y + dir[i][1];
    if (vis[fx][fy] || mp[fx][fy] == '.') continue;
    if (fx > 0 && fx <= n && fy > 0 && fy <= m) dfs(fx, fy);
  }
}
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= n; i++) scanf("%s", mp[i] + 1);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (!vis[i][j] && mp[i][j] == 'B') {
        dfs(i, j);
        ans++;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
