#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  char a[12][12];
  int w = 0, cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == 'P' && (a[i - 1][j] == 'W' || a[i][j - 1] == 'W' ||
                             a[i + 1][j] == 'W' || a[i][j + 1] == 'W'))
        cnt++;
      if (a[i][j] == 'W' && (a[i - 1][j] == 'P' || a[i][j - 1] == 'P' ||
                             a[i + 1][j] == 'P' || a[i][j + 1] == 'P'))
        w++;
    }
  }
  cout << min(w, cnt);
}
