#include <bits/stdc++.h>
using namespace std;
const long long N = 1e4 + 1;
char a[13][13];
bool used[13][13];
int n, m, cnt;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == 'W') {
        if (a[i][j - 1] == 'P' && !used[i][j - 1]) {
          used[i][j - 1] = 1;
          cnt++;
        } else if (a[i][j + 1] == 'P' && !used[i][j + 1]) {
          used[i][j + 1] = 1;
          cnt++;
        } else if (a[i - 1][j] == 'P' && !used[i - 1][j]) {
          used[i - 1][j] = 1;
          cnt++;
        } else if (a[i + 1][j] == 'P' && !used[i + 1][j]) {
          used[i + 1][j] = 1;
          cnt++;
        }
      }
    }
  }
  cout << cnt;
}
