#include <bits/stdc++.h>
using namespace std;
char O[15][15];
void Wolves(int n, int m) {
  int ans = 0, an = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (O[i][j] == 'W') {
        if (i != 0 && O[i - 1][j] != '.' && O[i - 1][j] != 'W') ++an;
        if (i != n - 1 && O[i + 1][j] != '.' && O[i + 1][j] != 'W') ++an;
        if (j != 0 && O[i][j - 1] != '.' && O[i][j - 1] != 'W') ++an;
        if (j != m - 1 && O[i][j + 1] != '.' && O[i][j + 1] != 'W') ++an;
      }
      if (an >= 1) {
        ++ans;
        an = 0;
      }
    }
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  char c;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> c;
      O[i][j] = c;
    }
  }
  Wolves(n, m);
  return 0;
}
