#include <bits/stdc++.h>
using namespace std;
int m, n, c;
char a[10][10];
int search(int i, int j) {
  if (i - 1 >= 0 && a[i - 1][j] == 'P') {
    c++;
    a[i - 1][j] = '.';
    return 0;
  }
  if (i + 1 < n && a[i + 1][j] == 'P') {
    c++;
    a[i + 1][j] = '.';
    return 0;
  }
  if (j - 1 >= 0 && a[i][j - 1] == 'P') {
    c++;
    a[i][j - 1] = '.';
    return 0;
  }
  if (j + 1 < m && a[i][j + 1] == 'P') {
    c++;
    a[i][j + 1] = '.';
    return 0;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int i, j;
  int x[1000], y[1000];
  int h = 0;
  int t = 1;
  while (t--) {
    c = 0;
    cin >> n >> m;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        cin >> a[i][j];
        if (a[i][j] == 'W') {
          x[h] = i;
          y[h] = j;
          h++;
        }
      }
    }
    for (i = 0; i < h; i++) {
      search(x[i], y[i]);
    }
    cout << c;
  }
}
