#include <bits/stdc++.h>
using namespace std;
bool sortBySec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.second < b.second);
}
bool prime(long long n) {
  if (n < 2) return false;
  for (long long x = 2; x * x <= n; x++) {
    if (n % x == 0) return false;
  }
  return true;
}
bool isPerfectSquare(long double x) {
  if (x >= 0) {
    long long sr = sqrt(x);
    return (sr * sr == x);
  }
  return false;
}
vector<long long> sieve(long long n) {
  long long *arr = new long long[n + 1]();
  vector<long long> vect;
  for (long long i = 2; i <= n; i++)
    if (arr[i] == 0) {
      vect.push_back(i);
      for (long long j = 2 * i; j <= n; j += i) arr[j] = 1;
    }
  return vect;
}
string decimalToBinary(long long n) {
  string s = bitset<64>(n).to_string();
  const auto loc1 = s.find('1');
  if (loc1 != string::npos) return s.substr(loc1);
  return "0";
}
void extendgcd(long long a, long long b, long long *v) {
  if (b == 0) {
    v[0] = 1;
    v[1] = 0;
    v[2] = a;
    return;
  }
  extendgcd(b, a % b, v);
  long long x = v[1];
  v[1] = v[0] - v[1] * (a / b);
  v[0] = x;
  return;
}
long long __gcd(long long a, long long b) {
  if (b > a) {
    return __gcd(b, a);
  }
  if (b == 0) {
    return a;
  }
  return __gcd(b, a % b);
}
long long expo(long long a, long long b, long long mod) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b = b >> 1;
  }
  return res;
}
long long mod_add(long long a, long long b, long long m) {
  a = a % m;
  b = b % m;
  return (((a + b) % m) + m) % m;
}
long long mod_mul(long long a, long long b, long long m) {
  a = a % m;
  b = b % m;
  return (((a * b) % m) + m) % m;
}
long long mod_sub(long long a, long long b, long long m) {
  a = a % m;
  b = b % m;
  return (((a - b) % m) + m) % m;
}
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
void solve() {
  long long n;
  long long m;
  cin >> n >> m;
  char a[n][m];
  for (long long i = 0; i < (n); ++i) {
    for (long long j = 0; j < (m); ++j) {
      cin >> a[i][j];
    }
  }
  long long count = 0;
  for (long long i = 0; i < (n); ++i) {
    for (long long j = 0; j < (m); ++j) {
      if (a[i][j] == 'W') {
        if (a[i][j - 1] == 'P' && j - 1 >= 0) {
          count++;
        } else if (a[i][j + 1] == 'P' && j + 1 < m) {
          count++;
        } else if (a[i - 1][j] == 'P' && i - 1 >= 0) {
          count++;
        } else if (a[i + 1][j] == 'P' && i + 1 < n) {
          count++;
        }
      }
    }
  }
  cout << (count) << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
