#include <bits/stdc++.h>
using namespace std;
int main() {
  int r, c;
  cin >> r >> c;
  r--;
  while (r--) {
    char p[c];
    for (int i = 0; i < c; i++) {
      cin >> p[i];
    }
  }
  char p[c + 2];
  for (int i = 1; i < c + 1; i++) {
    cin >> p[i];
  }
  p[c + 1] = '.';
  p[0] = '.';
  int ans = 0;
  for (int i = 0; i < c + 2; i++) {
    if (p[i] != p[i + 1]) {
      ans++;
    }
  }
  cout << ans / 2;
}
