#include <bits/stdc++.h>
using namespace std;
char ma[11][11];
int a[4] = {1, -1, 0, 0}, b[4] = {0, 0, 1, -1};
bool jq[11][11];
int main() {
  int n, m, i, j, sum;
  while (cin >> n >> m) {
    sum = 0;
    memset(jq, true, sizeof(jq));
    for (i = 1; i <= n; i++)
      for (j = 1; j <= m; j++) cin >> ma[i][j];
    for (i = 1; i <= n; i++)
      for (j = 1; j <= m; j++) {
        if (ma[i][j] == 'P') {
          for (int q = 0; q < 4; q++)
            if (i + a[q] >= 1 && i + a[q] <= n && j + b[q] >= 1 &&
                j + b[q] <= m && ma[i + a[q]][j + b[q]] == 'W' &&
                jq[i + a[q]][j + b[q]] == true) {
              sum++;
              jq[i + a[q]][j + b[q]] = false;
              break;
            }
        }
      }
    cout << sum << endl;
  }
  return 0;
}
