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