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