#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 100 + 5;

int n, m;
char gra[MAXN][MAXN];
short sum[MAXN][MAXN];
int ex, ey;
short f[MAXN][MAXN][MAXN][MAXN];

int get_sum(int x1, int y1, int x2, int y2)
{
	if(x1 > x2 || y1 > y2)
		return 0;
	return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];
}

int dp(int x1, int y1, int x2, int y2)
{
	if(x1 > x2 || y1 > y2)
		return 0;
	if(f[x1][y1][x2][y2] != -1)
		return f[x1][y1][x2][y2];
	int ret = 0, tot = get_sum(x1, y1, x2, y2);
	// cut left
	if(ret < tot)
		ret = max(ret, dp(x1, y1 + 1, x2, y2) + 
			(y1 + m - y2 < ey ? 0 : get_sum(max(x1, ex - n + x2), y1, min(x2, ex + x1 - 1), y1)));
	// cut right
	if(ret < tot)
		ret = max(ret, dp(x1, y1, x2, y2 - 1) +
			(y2 + 1 - y1 > ey ? 0 : get_sum(max(x1, ex - n + x2), y2, min(x2, ex + x1 - 1), y2)));
	// cut up
	if(ret < tot)
		ret = max(ret, dp(x1 + 1, y1, x2, y2) + 
			(x1 + n - x2 < ex ? 0 : get_sum(x1, max(y1, ey - m + y2), x1, min(y2, ey + y1 - 1))));
	// cut up
	if(ret < tot)
		ret = max(ret, dp(x1, y1, x2 - 1, y2) + 
			(x2 + 1 - x1 > ex ? 0 : get_sum(x2, max(y1, ey - m + y2), x2, min(y2, ey + y1 - 1))));
	// cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << ' ' << ret << endl;
	return f[x1][y1][x2][y2] = ret;
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		cin >> (gra[i] + 1);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
		{
			sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + (gra[i][j] == 'o');
			if(gra[i][j] == 'E')
				ex = i, ey = j;
		}
	// cout << sum[n][m] << endl;

	memset(f, -1, sizeof(f));

	int ans = dp(1, 1, n, m);

	cout << ans << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int line[110][110],col[110][110];
short dp[101][101][101][101];
int main()
{
	int n,m,x,y;scanf("%d%d\n",&n,&m);
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++)
	{
		line[i][j]=line[i][j-1];col[i][j]=col[i-1][j];
		char ch=getchar();
		if (ch=='E') {x=i;y=j;}
		else if (ch=='o') {line[i][j]++;col[i][j]++;}
		if (j==m) scanf("\n");
	}
	
	int all=0;
	for (int i=x;i>=1;i--)
	for (int j=y;j>=1;j--)
	for (int k=x;k<=n;k++)
	for (int l=y;l<=m;l++)
	{
		all=max(all,(int)dp[i][j][k][l]);
		if ((1<i)&&(k+1<x+i)) dp[i-1][j][k][l]=max((int)dp[i-1][j][k][l],dp[i][j][k][l]+line[i-1][min(l,m-y+j)]-line[i-1][max(j-1,l-y)]);
		if ((k<n)&&(x+k<n+i)) dp[i][j][k+1][l]=max((int)dp[i][j][k+1][l],dp[i][j][k][l]+line[k+1][min(l,m-y+j)]-line[k+1][max(j-1,l-y)]);
		if ((1<j)&&(l+1<y+j)) dp[i][j-1][k][l]=max((int)dp[i][j-1][k][l],dp[i][j][k][l]+col[min(k,n-x+i)][j-1]-col[max(i-1,k-x)][j-1]);
		if ((l<m)&&(y+l<m+j)) dp[i][j][k][l+1]=max((int)dp[i][j][k][l+1],dp[i][j][k][l]+col[min(k,n-x+i)][l+1]-col[max(i-1,k-x)][l+1]);
	}
	cout<<all<<endl;
}