#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long a, b, c, d;
bool possible(int x, int y) { return (x < n && x >= 0 && y < m && y >= 0); }
vector<long long> graph[1000012];
std::vector<std::vector<long long> > vis(102, std::vector<long long>(102, 0));
std::vector<string> grid;
void dfs(long long i, long long j) {
  vis[i][j] = 1;
  if (possible(i, j + 1) && vis[i][j + 1] == 0 && grid[i][j + 1] == 'B') {
    dfs(i, j + 1);
  }
  if (possible(i, j - 1) && vis[i][j - 1] == 0 && grid[i][j - 1] == 'B') {
    dfs(i, j - 1);
  }
  if (possible(i - 1, j) && vis[i - 1][j] == 0 && grid[i - 1][j] == 'B') {
    dfs(i - 1, j);
  }
  if (possible(i + 1, j) && vis[i + 1][j] == 0 && grid[i + 1][j] == 'B') {
    dfs(i + 1, j);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long H, e, D, C, w, z, x, y, i;
  long long l, r, Q;
  cin >> n >> m;
  std::vector<long long> v1;
  long long a, b, c;
  string s;
  for (long long i = 0; i < n; i++) {
    cin >> s;
    grid.push_back(s);
  }
  c = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (vis[i][j] == 0 && grid[i][j] == 'B') {
        dfs(i, j);
        c++;
      }
    }
  }
  cout << c;
  return 0;
}
