#include <bits/stdc++.h>
using namespace std;
int main() {
  char c;
  int a[12][12] = {0}, i, j, n, m, x, sum = 0;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      cin >> c;
      if (c == '.') {
        a[i][j] = 0;
      } else if (c == 'P') {
        a[i][j] = 1;
      } else
        a[i][j] = 2;
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (a[i][j] == 1) {
        if (a[i - 1][j] == 2) {
          a[i - 1][j] = 0;
          a[i][j] = 0;
          sum++;
        } else if (a[i][j - 1] == 2) {
          a[i][j - 1] = 0;
          a[i][j] = 0;
          sum++;
        } else if (a[i][j + 1] == 2) {
          a[i][j + 1] = 0;
          a[i][j] = 0;
          sum++;
        } else if (a[i + 1][j] == 2) {
          a[i + 1][j] = 0;
          a[i][j] = 0;
          sum++;
        }
      }
    }
  }
  cout << sum;
  return 0;
}
