#include <bits/stdc++.h>
using namespace std;
char a[11][11];
bool chk(int i, int j) {
  if (a[i + 1][j] == 'P') {
    a[i + 1][j] = '.';
    return true;
  } else if (a[i - 1][j] == 'P') {
    a[i - 1][j] = '.';
    return true;
  } else if (a[i][j + 1] == 'P') {
    a[i][j + 1] = '.';
    return true;
  } else if (a[i][j - 1] == 'P') {
    a[i][j - 1] = '.';
    return true;
  } else
    return false;
}
int main() {
  int r, c;
  cin >> r >> c;
  int ct = 0;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      if (a[i][j] == 'W') {
        if (chk(i, j)) ct++;
      }
    }
  }
  cout << ct << endl;
  return 0;
}
