#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  char arr[n][m];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) cin >> arr[i][j];
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (arr[i][j] == 'W') {
        if (i > 0 && arr[i - 1][j] == 'P')
          ans++;
        else if (i < n - 1 && arr[i + 1][j] == 'P')
          ans++;
        else if (j > 0 && arr[i][j - 1] == 'P')
          ans++;
        else if (j < m - 1 && arr[i][j + 1] == 'P')
          ans++;
      }
    }
  }
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  solve();
}
