#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int N = 105;
bool a[N][N], visited[N][N];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int r, c;
void bfs(int u, int v) {
  visited[u][v] = 1;
  queue<pair<int, int> > q;
  q.push({u, v});
  while (q.size()) {
    int x = q.front().first, y = q.front().second;
    q.pop();
    for (int i = 0; i <= 3; ++i) {
      int x1 = x + dx[i], y1 = y + dy[i];
      if (x1 < 0 || x1 >= r || y1 < 0 || y1 >= c || !a[x1][y1] ||
          visited[x1][y1])
        continue;
      visited[x1][y1] = 1;
      q.push({x1, y1});
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> r >> c;
  for (int i = 0; i <= r - 1; ++i) {
    memset(visited[i], (0), sizeof(visited[i]));
    memset(a[i], (0), sizeof(a[i]));
  }
  for (int i = 0; i <= r - 1; ++i) {
    for (int j = 0; j <= c - 1; ++j) {
      char d;
      cin >> d;
      a[i][j] = (d == 'B');
    }
  }
  int cnt = 0;
  for (int i = 0; i <= r - 1; ++i) {
    for (int j = 0; j <= c - 1; ++j) {
      if (!visited[i][j] && a[i][j]) {
        bfs(i, j);
        cnt++;
      }
    }
  }
  cout << cnt;
  return 0;
}
