#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int arr[20][20];
string s[20];
int n, m;
void fun(int a, int b) {
  if (a != 0 && arr[a - 1][b] == 1) {
    arr[a - 1][b] = -1;
    return;
  }
  if (b != 0 && arr[a][b - 1] == 1) {
    arr[a][b - 1] = -1;
    return;
  }
  if (b != m - 1 && arr[a][b + 1] == 1) {
    arr[a][b + 1] = -1;
    return;
  }
  if (a != n - 1 && arr[a + 1][b] == 1) {
    arr[a + 1][b] = -1;
    return;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < s.length(); j++) {
      if (s[j] == 'P')
        arr[i][j] = 1;
      else if (s[j] == 'W')
        arr[i][j] = 2;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr[i][j] == 2) fun(i, j);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (arr[i][j] == -1) ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
