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