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