#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  char arr[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf(" %c", &arr[i][j]);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr[i][j] == 'W') {
        if ((i + 1 < n && arr[i + 1][j] == 'P') ||
            (i - 1 >= 0 && arr[i - 1][j] == 'P') ||
            (j + 1 < m && arr[i][j + 1] == 'P') ||
            (j - 1 >= 0 && arr[i][j - 1] == 'P'))
          ans++;
      }
    }
  }
  printf("%d", ans);
  return 0;
}
