#include <bits/stdc++.h>
using namespace std;
char mat[101][101];
map<pair<long long int, long long int>, bool> vis;
map<pair<long long int, long long int>,
    vector<pair<long long int, long long int>>>
    adj;
void dfs(pair<long long int, long long int> v) {
  vis[v] = true;
  for (auto x : adj[v]) {
    if (!vis[x]) dfs(x);
  }
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 0; i < n; i += 1) {
    for (long long int j = 0; j < m; j += 1) {
      cin >> mat[i][j];
    }
  }
  for (long long int i = 0; i < n; i += 1) {
    for (long long int j = 0; j < m; j += 1) {
      if (mat[i][j] == 'B') {
        if (i != n - 1 and mat[i + 1][j] == 'B')
          adj[make_pair(i, j)].push_back(make_pair(i + 1, j)),
              adj[make_pair(i + 1, j)].push_back(make_pair(i, j));
        if (j != m - 1 and mat[i][j + 1] == 'B')
          adj[make_pair(i, j)].push_back(make_pair(i, j + 1)),
              adj[make_pair(i, j + 1)].push_back(make_pair(i, j));
      }
    }
  }
  long long int cnt = 0;
  for (long long int i = 0; i < n; i += 1) {
    for (long long int j = 0; j < m; j += 1) {
      if (mat[i][j] == 'B' and !vis[make_pair(i, j)])
        cnt++, dfs(make_pair(i, j));
    }
  }
  cout << cnt << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
  return 0;
}
