#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<vector<char> > g(n, vector<char>(m));
  char c;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> c;
      g[i][j] = c;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (g[i][j] == 'W') {
        for (int k = 0; k < 4; k++) {
          int tx = dx[k] + i;
          int ty = dy[k] + j;
          if (tx >= 0 && tx < n && ty >= 0 && ty < m && g[tx][ty] == 'P') {
            ans++;
            break;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
