#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  int x_axis;
  int y_axis;
  cin >> x_axis >> y_axis;
  char arr[x_axis][y_axis];
  for (int i = 0; i < x_axis; i++) {
    for (int j = 0; j < y_axis; j++) {
      cin >> arr[i][j];
    }
  }
  int count = 0;
  int a, b, c, d, e, f, g, h;
  for (int i = 0; i < x_axis; i++) {
    for (int j = 0; j < y_axis; j++) {
      e = j + 1;
      f = j - 1;
      g = i + 1;
      h = i - 1;
      if ((arr[i][j] == 'W')) {
        if (arr[i][e] == 'P' && (e >= 0 && e < y_axis)) {
          arr[i][e] = '.';
          arr[i][j] = '.';
          count++;
        } else if (arr[i][f] == 'P' && (f >= 0 && f < y_axis)) {
          arr[i][f] = '.';
          arr[i][j] = '.';
          count++;
        } else if (arr[g][j] == 'P' && (g >= 0 && g < x_axis)) {
          arr[g][j] = '.';
          arr[i][j] = '.';
          count++;
        } else if (arr[h][j] == 'P' && (h >= 0 && h < x_axis)) {
          arr[h][j] = '.';
          arr[i][j] = '.';
          count++;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}
