#include <bits/stdc++.h>
using namespace std;
string mult(string s1, string s2) {
  string s = "";
  int n1 = s1.length();
  int n2 = s2.length();
  int i, j, k, len, temp;
  char ch;
  for (i = 0; i < n1 + n2; i++) s = s + '0';
  len = max(n1, n2);
  for (i = n1 - 1; i >= 0; i--) {
    k = n1 - i - 1;
    temp = 0;
    for (j = n2 - 1; j >= 0; j--) {
      ch = ((s1[i] - '0') * (s2[j] - '0') + (s[k] - '0') + temp) % 10 + '0';
      temp = ((s1[i] - '0') * (s2[j] - '0') + (s[k] - '0') + temp) / 10;
      s[k] = ch;
      k++;
    }
    if (temp > 0) s[k] = s[k] + temp;
  }
  if (s[n1 + n2 - 1] == '0') s.erase(n1 + n2 - 1, 1);
  reverse(s.begin(), s.end());
  return s;
}
int a[9][9] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0,
               1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1,
               0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1,
               1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
int b[9][9] = {0};
int foot(int x1, int y1, int x2, int y2) {
  int len1 = 1000, len2 = 1000, len3 = 1000, len4 = 1000, len;
  if ((x1 == x2) && (y1 == y2)) {
    return 0;
  }
  if (x1 == 0 || y1 == 0) return 1000;
  b[x1][y1] = 1;
  if (x1 - 1 >= 0)
    if (a[x1 - 1][y1] == 0 && b[x1 - 1][y1] == 0) {
      len1 = foot(x1 - 1, y1, x2, y2) + 1;
    }
  if (y1 - 1 > 0)
    if (a[x1][y1 - 1] == 0 && b[x1][y1 - 1] == 0) {
      len2 = foot(x1, y1 - 1, x2, y2) + 1;
    }
  if (x1 + 1 < 9)
    if (a[x1 + 1][y1] == 0 && b[x1 + 1][y1] == 0) {
      len3 = foot(x1 + 1, y1, x2, y2) + 1;
    }
  if (y1 + 1 < 9)
    if (a[x1][y1 + 1] == 0 && b[x1][y1 + 1] == 0) {
      len4 = foot(x1, y1 + 1, x2, y2) + 1;
    }
  len = min(len1, min(len2, min(len3, len4)));
  b[x1][y1] = 0;
  return len;
}
int main(int argc, char** argv) {
  int m, n, i, j, ans = 0;
  cin >> m >> n;
  char ch[100][100];
  bool flag = false;
  for (i = 0; i < m; i++)
    for (j = 0; j < n; j++) cin >> ch[i][j];
  for (j = 0; j < n; j++)
    if (ch[m - 1][j] == 'B' && !flag) {
      ans++;
      flag = true;
    } else if (ch[m - 1][j] == '.')
      flag = false;
    else
      flag = true;
  cout << ans << endl;
  return 0;
}
