#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  t = 1;
  while (t--) {
    long long n, m, ans = 0;
    cin >> n >> m;
    string arr[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (arr[i][j] == 'W') {
          if (i && arr[i - 1][j] == 'P' || i + 1 < n && arr[i + 1][j] == 'P' ||
              j && arr[i][j - 1] == 'P' || j + 1 < m && arr[i][j + 1] == 'P') {
            ans++;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
