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