#include <bits/stdc++.h>
using namespace std;
int n, m;
bool isValid(int i, int j) { return (i >= 0 && i < n && j >= 0 && j < m); }
int main() {
  while (cin >> n >> m) {
    char arr[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> arr[i][j];
      }
    }
    int res = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (arr[i][j] == 'P') {
          if (isValid(i - 1, j) && arr[i - 1][j] == 'W') {
            res++;
            arr[i - 1][j] = '.';
          } else if (isValid(i + 1, j) && arr[i + 1][j] == 'W') {
            res++;
            arr[i + 1][j] = '.';
          } else if (isValid(i, j - 1) && arr[i][j - 1] == 'W') {
            res++;
            arr[i][j - 1] = '.';
          } else if (isValid(i, j + 1) && arr[i][j + 1] == 'W') {
            res++;
            arr[i][j + 1] = '.';
          }
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}
