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