#include "bits/stdc++.h"
using namespace std;
char t[3000][3000];
bool used[3000][3000];
int sum[3000][3000];
struct Data {
int i1 = 0, j1 = 0;
int i2 = 0, j2 = 0;
int i3 = 0, j3 = 0;
Data() = default;
static constexpr int H = 0;
static constexpr int V = 1;
Data(int i, int j, int t) {
if (t == H) {
tie(i1, j1) = tuple(i, j);
tie(i2, j2) = tuple(i, j + 1);
tie(i3, j3) = tuple(i, j + 2);
} else {
tie(i1, j1) = tuple(i, j);
tie(i2, j2) = tuple(i + 1, j);
tie(i3, j3) = tuple(i + 2, j);
}
}
bool check() const {
return !used[i1][j1] && !used[i2][j2] && !used[i3][j3];
}
void set() const {
used[i1][j1] = true;
used[i2][j2] = true;
used[i3][j3] = true;
}
void add() const {
sum[i1][j1] += 1;
sum[i2][j2] += 1;
sum[i3][j3] += 1;
}
void del() const {
sum[i1][j1] -= 1;
sum[i2][j2] -= 1;
sum[i3][j3] -= 1;
}
int get() const {
return max(sum[i1][j1], sum[i2][j2], sum[i3][j3]);
}
};
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> t[i][j];
}
}
vector<Data> all;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (j + 2 < m && t[i][j] == 'R' && t[i][j + 1] == 'G' && t[i][j + 2] == 'W') {
all.emplace_back(i, j, Data::H);
all.back().add();
}
if (i + 2 < n && t[i][j] == 'R' && t[i + 1][j] == 'G' && t[i + 2][j] == 'W') {
all.emplace_back(i, j, Data::V);
all.back().add();
}
}
}
int ans = 0;
while (!all.empty()) {
auto it = min_element(all.begin(), all.end(), [](const auto &A, const auto &B) {
return A.get() < B.get();
});
swap(*it, all.back());
Data cur = all.back();
all.pop_back();
cur.del();
if (cur.check()) {
cur.set();
ans += 1;
}
}
cout << ans << '\n';
return 0;
}