#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n, c = 0;
  cin >> n >> m;
  char s;
  int p = int('P');
  int w = int('W');
  int arr[n + 2][m + 2];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> s;
      arr[i][j] = int(s);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (arr[i][j] == w) {
        if (arr[i + 1][j] == p || arr[i - 1][j] == p || arr[i][j + 1] == p ||
            arr[i][j - 1] == p) {
          c++;
        }
      }
    }
  }
  cout << c;
  return 0;
}
