#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long n, m, viz[101][101], ans = 0;
char a[101][101];
void dfs(long long x, long long y) {
  viz[x][y] = 1;
  if (viz[x + 1][y] == 0 && x + 1 < n && a[x + 1][y] == 'B') {
    viz[x + 1][y] = 1;
    dfs(x + 1, y);
  }
  if (viz[x - 1][y] == 0 && x - 1 >= 0 && a[x - 1][y] == 'B') {
    viz[x - 1][y] = 1;
    dfs(x - 1, y);
  }
  if (viz[x][y + 1] == 0 && y + 1 < m && a[x][y + 1] == 'B') {
    viz[x][y + 1] = 1;
    dfs(x, y + 1);
  }
  if (viz[x][y - 1] == 0 && y - 1 >= 0 && a[x][y - 1] == 'B') {
    viz[x][y - 1] = 1;
    dfs(x, y - 1);
  }
}
int32_t main() {
  ios_base::sync_with_stdio();
  cin.tie();
  cout.tie();
  ;
  cin >> n;
  cin >> m;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> a[i][j];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++)
      if (a[i][j] == 'B' && viz[i][j] == 0) {
        dfs(i, j);
        ans++;
      }
  cout << ans << endl;
}
