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