#include <bits/stdc++.h>
using namespace std;
vector<long long> v1;
vector<long long> v2;
vector<pair<long long, long long> > vp;
int main() {
  ios_base::sync_with_stdio(0);
  long long n, i, j, m, ctr = 0;
  ;
  string s;
  cin >> n >> m;
  char a[11][11];
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      if (a[i][j] == 'W' && (a[i - 1][j] == 'P' || a[i + 1][j] == 'P' ||
                             a[i][j - 1] == 'P' || a[i][j + 1] == 'P'))
        ctr++;
    }
  cout << ctr;
  return 0;
}
