#include <bits/stdc++.h>
using namespace std;
char S[1001][1001];
map<string, int> mp;
int main() {
  int B, N, i, mx = 0, cnt, ind, t, j;
  cin >> N >> B;
  getchar();
  for (i = 0; i < N; i++) gets(S[i]);
  for (i = 0; i < N; i++)
    for (j = 0; j < B; j++)
      if (S[i][j] == 'W') {
        if (S[i][j + 1] == 'P') {
          mx++;
          S[i][j + 1] = '.';
        } else if (S[i][j - 1] == 'P') {
          mx++;
          S[i][j - 1] = '.';
        } else if (S[i - 1][j] == 'P') {
          mx++;
          S[i - 1][j] = '.';
        } else if (S[i + 1][j] == 'P') {
          mx++;
          S[i + 1][j] = '.';
        }
      }
  cout << mx << endl;
  return 0;
}
