#include <bits/stdc++.h>
using namespace std;
long long int dx[] = {-1, +1, 0, 0, +1, -1, +1, -1};
long long int dy[] = {0, 0, -1, +1, +1, +1, -1, -1};
const long long int mx = 1e5 + 123;
const long long int MOD = 1e9 + 7;
const long long int INF = LLONG_MAX;
template <class T>
T power(T a, T b) {
  a %= MOD;
  if (!a) return 0;
  T p = 1;
  while (b > 0) {
    if (b & 1) {
      p *= a;
      p %= MOD;
    }
    a *= a;
    a %= MOD;
    b = b >> 1;
  }
  return p;
}
template <class T>
void print(vector<T> &v) {
  for (T u : v) {
    cout << u << " ";
  }
  cout << endl;
}
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long int a, b, i, j, x, ans = 0, y = 0;
  cin >> a >> b;
  char c[a][b];
  string s = ".";
  for (__typeof(a) i = (0) - (0 > a); i != (a) - (0 > a);
       i += 1 - 2 * (0 > a)) {
    for (__typeof(b) j = (0) - (0 > b); j != (b) - (0 > b);
         j += 1 - 2 * (0 > b)) {
      cin >> c[i][j];
      if (i == a - 1) {
        s += c[i][j];
      }
    }
  }
  for (__typeof(s.size() - 1) i = (0) - (0 > s.size() - 1);
       i != (s.size() - 1) - (0 > s.size() - 1);
       i += 1 - 2 * (0 > s.size() - 1))
    if (s[i] == '.' && s[i + 1] == 'B') ans++;
  cout << ans << endl;
  return 0;
}
