#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, count = 0, k, l, f;
  char temp;
  char arr[11][11];
  int r[4] = {1, -1, 0, 0};
  int c[4] = {0, 0, -1, 1};
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> arr[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (arr[i][j] == 'W') {
        f = 0;
        for (int h = 0; h < 4; h++) {
          k = i + r[h];
          l = j + c[h];
          if (k < n && l < m)
            if (arr[k][l] == 'P' && f == 0) {
              count++;
              f = 1;
            }
        }
      }
    }
  cout << count;
  return 0;
}
