#include <bits/stdc++.h>
using namespace std;
char ch[1001][1001];
int kol, n, m;
inline long long mult(long long a, long long b, long long mod) {
  if (b == 0) return 0;
  if (b % 2 == 1) return (mult(a, b - 1, mod) + a) % mod;
  return (mult(a, b / 2, mod) * 2) % mod;
}
inline long long BinPow(long long a, long long b, long long mod) {
  if (b == 0) return 1;
  if (b == 1) return a;
  if (b % 2 == 1) return (mult(BinPow(a, b - 1, mod), a, mod)) % mod;
  long long res = BinPow(a, b / 2, mod);
  return mult(res, res, mod);
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> ch[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (ch[i][j] == 'W')
        if (ch[i + 1][j] == 'P' || ch[i][j + 1] == 'P' || ch[i][j - 1] == 'P' ||
            ch[i - 1][j] == 'P')
          kol++;
  cout << kol;
  return 0;
}
