#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
#define si short int
using namespace std;
const int N=101;
si n,m,x,y,ans,dp[N][N][N][N],sum[N][N];
char g[N][N];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
template<typename I>inline I mx(const I&a,const I&b){return a>b ? a : b;}
template<typename I>inline I mi(const I&a,const I&b){return a<b ? a : b;}
template<typename I>inline void swp(I&a,I&b){I t=a; a=b; b=t;}
inline void cmx(si &a,si b){if(b>a) a=b;}
inline si s(int a,int b,int c,int d){
	if(a>c) swp(a,c); if(b>d) swp(b,d);
	return sum[c][d]-sum[c][b-1]-sum[a-1][d]+sum[a-1][b-1];
}
int main()
{
//	freopen("Salvage Robots.in","r",stdin);
	read(n,m);
	for(RG int i=1;i<=n;i++) 
	{
		scanf("%s",g[i]+1);
		for(RG int j=1;j<=m;j++)
		{
			if(g[i][j]=='o') sum[i][j]=1;
			else if(g[i][j]=='E') x=i, y=j;
			sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
		}
	}
	for(int i=x;i;i--)
	 for(int j=y;j;j--)
	  for(int k=x;k<=n;k++)
	   for(int l=y;l<=m;l++)
	   {
			ans=mx(ans,dp[i][j][k][l]);
			int li=l-y+1, ri=m-y+j, us=k-x+1, ds=n-x+i;
			if(i-1>=us) cmx(dp[i-1][j][k][l],dp[i][j][k][l]+s(i-1,mx(li,j),i-1,mi(ri,l)));
			if(j-1>=li) cmx(dp[i][j-1][k][l],dp[i][j][k][l]+s(mx(i,us),j-1,mi(k,ds),j-1));
			if(k+1<=ds) cmx(dp[i][j][k+1][l],dp[i][j][k][l]+s(k+1,mx(li,j),k+1,mi(ri,l)));
			if(l+1<=ri) cmx(dp[i][j][k][l+1],dp[i][j][k][l]+s(mx(i,us),l+1,mi(k,ds),l+1));
	   }
	cout<<ans<<endl;
	return 0;
}
#include<bits/stdc++.h>
using namespace std;

#define MAX 102

int h;
int w;

char buf[MAX][MAX];

short dp[MAX][MAX][MAX][MAX];
pair<int, int> E;
int im[MAX][MAX];
int gt(int a, int b){
	if (a < 0 || b < 0){
		return 0;
	}
	return im[a][b];
}
int rect(int x1, int x2, int y1, int y2){
	return gt(x2, y2) + gt(x1 - 1, y1 - 1) - gt(x2, y1 - 1) - gt(x1 - 1, y2);
}
int dfs(int a, int b, int c, int d){
	if (a > b || c > d)return 0;
	return dp[a][b][c][d];
}
int main(){
	cin >> h >> w;
	for (int i = 0; i < h; i++){
		scanf("%s", buf[i]);
	}
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			if (buf[i][j] == 'E'){
				E = make_pair(i, j);
			}
			if (buf[i][j] == 'o'){
				im[i][j]++;
			}
		}
	}
	for (int i = 0; i < h; i++){
		for (int j = 1; j < w; j++){
			im[i][j] += im[i][j - 1];
		}
	}
	for (int j = 0; j < w; j++){
		for (int i = 1; i < h; i++){
			im[i][j] += im[i - 1][j];
		}
	}
	int a;
	int b;
	int c;
	int d;
	short int can;
	short int add;
	for (int rng = 1; rng <= h; rng++){
		for (int rng2 = 1; rng2 <= w; rng2++){
			for (int i = 0; i + rng <= h; i++){
				for (int j = 0; j + rng2 <= w; j++){
					a = i;
				 b = a + rng - 1;
					c = j;
					d = j + rng2 - 1;
					{
						can = E.first + a + 1;
						if (a + 1 <= can&&can <= b){
							add = rect(can, can, max(c, E.second - (w - d) + 1), min(d, E.second + c));
							add += dfs(a + 1, b, c, d);
							dp[a][b][c][d] = add;
						}
					}

					//choose b
					{
					 can = E.first - (h - b);
						if (a <= can&&can <= b - 1){
						 add = rect(can, can, max(c, E.second - (w - d) + 1), min(d, E.second + c));
							add += dfs(a, b - 1, c, d);
							dp[a][b][c][d] = max(dp[a][b][c][d], add);
						}
					}
					//choose c
					{
						can = E.second + c + 1;
						if (c + 1 <= can&&can <= d){
							add = rect(max(a, E.first - (h - b) + 1), min(b, E.first + a), can, can);
							add += dfs(a, b, c + 1, d);
							dp[a][b][c][d] = max(dp[a][b][c][d], add);
						}
					}
					//choose d
					{
						can = E.second - (w - d);
						if (c <= can&&can <= d - 1){
							add = rect(max(a, E.first - (h - b) + 1), min(b, E.first + a), can, can);
							add += dfs(a, b, c, d - 1);
							dp[a][b][c][d] = max(dp[a][b][c][d], add);
						}
					}
				}
			}
		}
	}
	
	int ans=dfs(0, h - 1, 0, w - 1);
	cout << ans << endl;
	return 0;
}