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