#include <bits/stdc++.h>
using namespace std;
char arr[105][105];
long long int n, m;
void bfs(long long int i, long long int j) {
  queue<pair<long long int, long long int>> qq;
  qq.push({i, j});
  arr[i][j] = '.';
  while (!qq.empty()) {
    pair<long long int, long long int> temp = qq.front();
    qq.pop();
    long long int a = temp.first;
    long long int b = temp.second;
    if (a + 1 < n && arr[a + 1][b] == 'B') {
      arr[a + 1][b] = '.';
      qq.push({a + 1, b});
    }
    if (a - 1 >= 0 && arr[a - 1][b] == 'B') {
      arr[a - 1][b] = '.';
      qq.push({a - 1, b});
    }
    if (b + 1 < m && arr[a][b + 1] == 'B') {
      arr[a][b + 1] = '.';
      qq.push({a, b + 1});
    }
    if (b - 1 >= 0 && arr[a][b - 1] == 'B') {
      arr[a][b - 1] = '.';
      qq.push({a, b - 1});
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  t = 1;
  while (t--) {
    cin >> n >> m;
    for (long long int i = 0; i < n; i++)
      for (long long int j = 0; j < m; j++) cin >> arr[i][j];
    long long int count = 0;
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < m; j++) {
        if (arr[i][j] == 'B') {
          count++;
          bfs(i, j);
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}
