#include <bits/stdc++.h>
using namespace std;
int pi[] = {1, 0, -1, 0};
int pj[] = {0, -1, 0, 1};
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<char> > v(n, vector<char>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> v[i][j];
    }
  }
  int ct = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (v[i][j] != 'W') continue;
      for (int z = 0; z < 4; z++) {
        int y = i + pi[z], x = j + pj[z];
        if (y < 0 or y >= n or x < 0 or x >= m or v[y][x] != 'P') continue;
        ct++;
        break;
      }
    }
  }
  cout << ct << endl;
}
