// Born_To_Laugh - Hughie Do
#include <bits/stdc++.h>
#define alle(AC) AC.begin(), AC.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
[[maybe_unused]] const int MOD = 998244353, INF = 1e9 + 7;
const int maxn = 3010;
int n, m;
int a[maxn][maxn];
ll dp[maxn][3];
void solve(){
cin >> n >> m;
for(int i=1; i<=n; ++i){
for(int j=1; j<=m; ++j){
char x;cin >> x;
if(x == 'R') a[i][j] = 1;
if(x == 'G') a[i][j] = 2;
if(x == 'W') a[i][j] = 3;
}
}
ll ans = 0;
for(int c=2; c <= n + m; ++c){
ll cur = 0;
for(int i=1; i<=n; ++i){
int j = c - i;
if(j < 1 || j > m) continue;
dp[i][0] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]});
if(a[i][j] == 2){
if((j > 1 && a[i][j - 1] == 1) && (j < m && a[i][j + 1] == 3)){
dp[i][1] = max(dp[i][1], max(dp[i - 1][1], dp[i - 1][0]) + 1);
}
if((i > 1 && a[i - 1][j] == 1) && (i < n && a[i + 1][j] == 3)){
dp[i][2] = max(dp[i][2], max(dp[i - 1][2], dp[i - 1][0]) + 1);
}
}
cur = max({cur, dp[i][0], dp[i][1], dp[i][2]});
}
ans += cur;
for(int i=1; i<=n; ++i) dp[i][0] = dp[i][1] = dp[i][2] = 0;
}
cout << ans << '\n';
}
signed main(){
// freopen("inp.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}