#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  char c[12][13];
  string temp;
  for (int i = 1; i <= n; i++) {
    cin >> temp;
    int t = 0;
    for (int j = 1; j <= m; j++) {
      c[i][j] = temp[t++];
    }
  }
  int maxp = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (c[i][j] == 'W') {
        if (c[i - 1][j] == 'P' || c[i + 1][j] == 'P' || c[i][j - 1] == 'P' ||
            c[i][j + 1] == 'P') {
          maxp += 1;
        }
      }
    }
  }
  cout << maxp;
  return 0;
}
