#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
double PI = 3.1415926535897932384626433832795;
double EPS = 1e-2;
const int MAXN = 1000;
const int MAXC = 1e7;
const int mod = 1e9 + 7;
inline int mul(int a, int b) {
  if (a < 0) a += mod;
  if (b < 0) b += mod;
  return (a * (long long)b) % mod;
}
inline int sum(int a, int b) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}
inline int sub(int a, int b) {
  a -= b;
  if (a < 0) a += mod;
  return a;
}
inline int pw(int base, int deg) {
  int res = 1;
  while (deg) {
    if (deg & 1) res = mul(base, res);
    base = mul(base, base);
    deg >>= 1;
  }
  return res;
}
int n, m;
vector<vector<int> > gr;
long long ans = 0;
int was[MAXN][MAXN];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
char mas[MAXN][MAXN];
int ok(int x, int y) {
  if (x < 0 || x >= n || y < 0 || y >= m || mas[x][y] == '.') return 0;
  return 1;
}
void dfs(int x, int y) {
  was[x][y] = 1;
  for (int i = 0; i < 4; ++i) {
    int tx = x + dx[i], ty = y + dy[i];
    if (ok(tx, ty) && !was[tx][ty]) dfs(tx, ty);
  }
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> mas[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (mas[i][j] == 'B' && !was[i][j]) {
        ans++;
        dfs(i, j);
      }
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  srand(1313);
  int t = 1;
  for (int i = 0; i < t; ++i) {
    solve();
  }
  return 0;
}
