#include <bits/stdc++.h>
using namespace std;
vector<int> v, r;
int m, n, w, sw;
int X[4]{-1, 0, 1, 0};
int Y[4]{0, -1, 0, 1};
string s[11];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == 'W') {
        w++;
        for (int x = 0; x < 4; ++x) {
          if (i + X[x] >= 0 && j + Y[x] >= 0) {
            if (s[i + X[x]][j + Y[x]] == 'P') {
              sw++;
              break;
            }
          }
        }
      }
    }
  }
  printf("%d\n", min(sw, w));
  return 0;
}
