#include <bits/stdc++.h>
using namespace std;
int n, j, t, l, r, m, z, d, k, c, x, y, i;
char a[320][320];
int main() {
  cin >> n >> m;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) cin >> a[i][j];
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      if (a[i][j] == 'W' && a[i][j - 1] == 'P') {
        a[i][j - 1] = '.';
        k++;
      } else if (a[i][j] == 'W' && a[i][j + 1] == 'P') {
        a[i][j + 1] = '.';
        k++;
      } else if (a[i][j] == 'W' && a[i - 1][j] == 'P') {
        a[i - 1][j] = '.';
        k++;
      } else if (a[i][j] == 'W' && a[i + 1][j] == 'P') {
        a[i + 1][j] = '.';
        k++;
      }
  cout << k;
}
