#include <algorithm>
#include <cstdio>
#define upd(x, y) (x) = std::max(x, y)
char str[105];
int dp[105][105][105][105], row_pre[105][105], col_pre[105][105];
int main()
{
	// freopen("AGC004-E.in", "r", stdin);
	int n, m, x, y;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
	{
		scanf("%s", str);
		for (int j = 0; j < m; j++)
		{
			row_pre[i][j] = (j ? row_pre[i][j - 1] : 0) + (str[j] == 'o');
			col_pre[j][i] = (i ? col_pre[j][i - 1] : 0) + (str[j] == 'o');
			if (str[j] == 'E')
			{
				x = i;
				y = j;
			}
		}
	}
	auto calc_row = [&] (int row, int l, int r)
	{
		int L = std::max(l, r - y), R = std::min(r, l + m - y - 1);
		return L <= R ? row_pre[row][R] - (L ? row_pre[row][L - 1] : 0) : 0;
	};
	auto calc_col = [&] (int col, int l, int r)
	{
		int L = std::max(l, r - x), R = std::min(r, l + n - x - 1);
		return L <= R ? col_pre[col][R] - (L ? col_pre[col][L - 1] : 0) : 0;
	};
	for (int i = 0; i <= x; i++)
	{
		for (int j = n - 1; j >= x; j--)
		{
			for (int k = 0; k <= y; k++)
			{
				for (int t = m - 1; t >= y; t--)
				{
					if (j - i < x)
						upd(dp[i][j][k][t], dp[i - 1][j][k][t] + calc_row(i - 1, k, t));
					if (j - i < n - x - 1)
						upd(dp[i][j][k][t], dp[i][j + 1][k][t] + calc_row(j + 1, k, t));
					if (t - k < y)
						upd(dp[i][j][k][t], dp[i][j][k - 1][t] + calc_col(k - 1, i, j));
					if (t - k < m - y - 1)
						upd(dp[i][j][k][t], dp[i][j][k][t + 1] + calc_col(t + 1, i, j));
				}
			}
		}
	}
	printf("%d\n", dp[x][x][y][y]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N=110, M=5e3+300;
int h,w,F[M][M],idh[N][N],idw[N][N];
char mp[N][N]; int stx,sty,s[N][N];
inline int& f(int l,int r,int u,int d) {return F[idh[l][r]][idw[u][d]];}
inline int getarea(int xc1,int xc2,int yc1,int yc2) {
    return s[xc2][yc2]-s[xc1-1][yc2]-s[xc2][yc1-1]+s[xc1-1][yc1-1];
}
inline int calcl(int p,int up,int dn,int l,int r,int u,int d) {
    if(p<=r || p+l>w) return 0;
    up=max(up,d+1); dn=min(dn,h-u);
    if(up>dn) return 0;
    return getarea(up,dn,p,p);
}
inline int calcr(int p,int li,int ri,int l,int r,int u,int d) {
    if(p<=d || p+u>h) return 0;
    li=max(li,r+1); ri=min(ri,w-l);
    if(li>ri) return 0;
    return getarea(p,p,li,ri);
}
int main() {
    cin>>h>>w; 
    for(int i=1;i<=h;i++) cin>>(mp[i]+1);
    for(int i=1;i<=h;i++) 
        for(int j=1;j<=w;j++) {
            if(mp[i][j]=='o') s[i][j]=1;
            if(mp[i][j]=='E') stx=i, sty=j;
            s[i][j]=s[i][j-1]+s[i-1][j]-s[i-1][j-1]+s[i][j];
        }
    for(int l=0,cnt=0;l<=sty;++l)
        for(int r=0;sty+r<=w;++r)
            idh[l][r]=cnt++;
    for(int u=0,cnt=0;u<=stx;++u)
        for(int d=0;d+stx<=h;++d)
            idw[u][d]=cnt++;

    int ans=0;
    for(int l=0;l<=sty;++l)
        for(int r=0;sty+r<=w;++r)
            for(int u=0;u<=stx;++u)
                for(int d=0;d+stx<=h;++d) {
                    int &s=f(l,r,u,d);
                    if(l) s=max(s,f(l-1,r,u,d)+calcl(sty-l,stx-u,stx+d,l-1,r,u,d));
                    if(r) s=max(s,f(l,r-1,u,d)+calcl(sty+r,stx-u,stx+d,l,r-1,u,d));
                    if(u) s=max(s,f(l,r,u-1,d)+calcr(stx-u,sty-l,sty+r,l,r,u-1,d));
                    if(d) s=max(s,f(l,r,u,d-1)+calcr(stx+d,sty-l,sty+r,l,r,u,d-1));
                    ans=max(ans,s);
                }
    cout<<ans<<'\n';
}