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