#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//#define int ll
using P = pair<int, int>;
#define all(x) x.begin(), x.end()
#define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e)?x++:x--))
#define sz(x) (int)x.size()
const char nl = '\n';
const int N = 3001;
vector<string> a;
vector<int> g2[N][N];
vector<int> g[N*N];
int color[N*N];
bool c3(int i, int j) {
return a[i][j] == 'R' && a[i][j+1] == 'G' && a[i][j+2] == 'W';
}
bool c2(int i, int j) {
return a[i][j] == 'R' && a[i+1][j] == 'G' && a[i+2][j] == 'W';
}
int c = 0;
void gos2(int i, int j) {
rep(p, 0, 3) {
for (auto k: g2[i+p][j])
g[c].push_back(k),
g[k].push_back(c);
g2[i+p][j].push_back(c);
}
}
void gos3(int i, int j) {
rep(p, 0, 3) {
for (auto k: g2[i][j+p])
g[c].push_back(k),
g[k].push_back(c);
g2[i][j+p].push_back(c);
}
}
int cnt1, cnt2;
void dfs(int nd, int col) {
color[nd] = col;
if (col>0)cnt1 += 1;
else cnt2 += 1;
for (auto i: g[nd])
if (!color[i])
dfs(i, -col);
else if (color[i] != -col)assert(1==0);
}
void solve() {
int n, m; cin >> n >> m;
a.resize(n);
for (auto &i: a)cin >> i;
int cnt = 0;
rep(i, 0, n) {
rep(j, 0, m) {
if (i<n-2 && c2(i, j)) {
c += 1;
gos2(i, j);
}
if(j<m-2&&c3(i, j)) {
c += 1;
gos3(i, j);
}
}
}
int res = 0;
rep(nd, 1, c+1)
if (!color[nd]) {
dfs(nd, 1);
res += max(cnt1, cnt2);
cnt1 = cnt2 = 0;
}
cout << res << nl;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
//RRRGW
//RRGRR
//RGWWR
/*
* RGW
* GRGW
* WGR
* RWG
* GRGW
* WG
* W
*
*/