#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;

int num[100][100];
int h, w;
char mp[100][100];
int calc(int lx, int ly, int rx, int ry) {
	if (lx > rx || ly > ry)return 0;
	int ret = num[rx][ry];
	if (lx > 0)ret -= num[lx - 1][ry];
	if (ly > 0)ret -= num[rx][ly - 1];
	if (lx > 0 && ly > 0)ret += num[lx - 1][ly - 1];
	return ret;
}
int sx, sy;
void hanten_h() {
	rep(j, w) {
		rep(i, h / 2) {
			swap(mp[i][j], mp[h - 1 - i][j]);
		}
	}
	rep(i, h) {
		rep(j, w) {
			if (mp[i][j] == 'E') {
				sx = i, sy = j;
			}
		}
	}
}
void hanten_w() {
	rep(i, h) {
		rep(j, w / 2) {
			swap(mp[i][j], mp[i][w - 1 - j]);
		}
	}
	rep(i, h) {
		rep(j, w) {
			if (mp[i][j] == 'E') {
				sx = i, sy = j;
			}
		}
	}
}
typedef vector<vec> mat;
int query(mat a, mat b) {
	int n = a.size(); if (n == 0)return 0;
	//assert(b.size() == n);
	int m = a[0].size(); if (m == 0)return 0;
	//assert(b[0].size() == m);
	vector<int> dp(n + 1);
	rep(j, m) {
		int ma = 0;
		int num = 0;
		rep(k, n) {
			if (b[k][j])num++;
		}
		ma = dp[0]; dp[0] = ma + num;
		rep1(i, n) {
			ma = max(ma, dp[i]);
			if (b[i - 1][j])num--;
			if (a[i - 1][j])num++;
			dp[i] = ma + num;
		}
	}
	int ret = 0;
	rep(i, n + 1) {
		ret = max(ret, dp[i]);
	}
	return ret;
}
mat trans(int lx, int ly, int rx, int ry) {
	mat ret(rx - lx + 1);
	Rep1(i, lx, rx) {
		ret[i - lx].resize(ry - ly + 1,0);
		Rep1(j, ly, ry) {
			if (mp[i][j] == 'o') {
				ret[i - lx][j - ly] = 1;
			}
		}
	}
	return ret;
}
void solve() {
	cin >> h >> w;
	rep(i, h) {
		rep(j, w) {
			cin >> mp[i][j];
			if (mp[i][j] == 'E') {
				sx = i, sy = j;
			}
		}
	}
	if (sx >= (h+1) / 2) {
		hanten_h();
	}
	if (sy >= (w + 1) / 2) {
		hanten_w();
	}
	rep(i, h) {
		rep(j, w) {
			if (mp[i][j] == 'o') {
				num[i][j] = 1;
			}
			if (i > 0)num[i][j] += num[i - 1][j];
			if (j > 0)num[i][j] += num[i][j - 1];
			if (i > 0 && j > 0) {
				num[i][j] -= num[i - 1][j - 1];
			}
		}
	}
	int ans = 0;
	for (int lx = 0; lx <= sx; lx++) {
		int rx = h - 1 - (sx - lx);
		int ex = sx + lx;
		for (int ly = 0; ly <= sy; ly++) {
			int ry = w - 1 - (sy - ly);
			int ey = sy + ly;
			int sum = calc(lx, ly, rx, ry);
			int lenx = rx - ex; int leny = ry - ey;
			sum -= calc(ex + 1, ly, rx, ly + leny - 1);
			sum -= calc(lx, ey + 1, lx + lenx - 1, ry);
			mat A = trans(ex + 1, ly, rx, ly + leny - 1);
			mat B = trans(lx, ey + 1, lx + lenx - 1, ry);
			ans = max(ans, sum + query(A, B));
		}

	}
	cout << ans << endl;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//init();
	solve();

	//cout << "finish" << endl;
	//stop
	return 0;
}

Measured memory_bytes: 648