#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int n, m;
int x, y;

int a[110][110];

char buf[110];
void in(){
	read(n, m);
	for(int i=1; i<=n; ++i){
		scanf("%s", buf+1);
		for(int j=1; j<=m; ++j){
			a[i][j]=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
			if(buf[j] == 'o'){
				++a[i][j];
			} else if(buf[j] == 'E'){
				x=i; y=j;
			}
		}
	}
}

int dp[102][102][102][102];

int rect(int L1, int R1, int D1, int U1, int L2, int R2, int D2, int U2){
	int L=max(L1, L2);
	int R=min(R1, R2);
	int D=max(D1, D2);
	int U=min(U1, U2);
	if(L>R || D>U) return 0;
	if(0) printf("%d %d %d %d\n", L, R, D, U);
	return a[R][U]-a[L-1][U]-a[R][D-1]+a[L-1][D-1];
}

int main()
{
	in();
	for(int w=1; w<=n; ++w){
		for(int h=1; h<=m; ++h){
			for(int l=1; l+w-1<=n; ++l){
				int r=l+w-1;
				if(x<l || r<x) continue;
				for(int d=1; d+h-1<=m; ++d){
					int u=d+h-1;
					if(y<d || u<y) continue;
					int me=dp[l][r][d][u];
					auto f = [&](int A, int B, int C, int D){
						int I=l+A;
						int J=r+B;
						int K=d+C;
						int L=u+D;
						int nv = rect(1+(r-x), n-(x-l), 1+(u-y), m-(y-d),
							(A||B)?(A?I:J):(I),
							(A||B)?(A?I:J):(J),
							(C||D)?(C?K:L):(K),
							(C||D)?(C?K:L):(L)
						);
						int& T=dp[I][J][K][L];
						if(T < me+nv){
							if(0) printf("upd from %d-%d, %d-%d to df %d %d %d %d : %d+%d = %d\n",
								l,r,d,u, A,B,C,D, me, nv, me+nv);
						}
						T=max(T, me+nv);
					};
					if(1 < l) f(-1, 0, 0, 0);
					if(r < n) f(0, 1, 0, 0);
					if(1 < d) f(0, 0, -1, 0);
					if(u < m) f(0, 0, 0, 1);
				}
			}
		}
	}
	printf("%d\n", dp[1][n][1][m]);
	return 0;
}

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

// 累積和（2次元）
template <class T>
class cumulativeSum
{
private:
    int ny, nx;
    vector<vector<T> > sum;
public:
    cumulativeSum(const vector<vector<T> >& a)
    {
        ny = a.size();
        nx = a[0].size();
        sum.assign(ny+1, vector<T>(nx+1, 0));
        for(int i=0; i<ny; ++i){
            for(int j=0; j<nx; ++j){
                sum[i+1][j+1] = a[i][j] + sum[i][j+1] + sum[i+1][j] - sum[i][j];
            }
        }
    }
    T getSum(int y1, int x1, int y2, int x2)
    {
        y1 = max(y1, 0);
        x1 = max(x1, 0);
        y2 = min(y2, ny-1);
        x2 = min(x2, nx-1);
        if(y1 > y2 || x1 > x2)
            return 0;
        return sum[y2+1][x2+1] - sum[y1][x2+1] - sum[y2+1][x1] + sum[y1][x1];
    }
};

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<int> > s(h, vector<int>(w, 0));
    int ey, ex;
    for(int y=0; y<h; ++y){
        for(int x=0; x<w; ++x){
            char c;
            cin >> c;
            if(c == 'E'){
                ey = y;
                ex = x;
            }
            else if(c == 'o'){
                s[y][x] = 1;
            }
        }
    }
    cumulativeSum<int> cs(s);

    int up    = ey;
    int down  = h - 1 - ey;
    int left  = ex;
    int right = w - 1 - ex;
    vector<vector<vector<vector<int> > > > dp(up+1, vector<vector<vector<int> > >(down+1, vector<vector<int> >(left+1, vector<int>(right+1, 0))));
    int ans = 0;
    for(int u=0; u<=up; ++u){
        for(int d=0; d<=down; ++d){
            for(int l=0; l<=left; ++l){
                for(int r=0; r<=right; ++r){
                    ans = max(ans, dp[u][d][l][r]);

                    int y1 = max(ey - u, d);
                    int y2 = min(ey + d, h - 1 - u);
                    if(ex - 1 - l >= r)
                        dp[u][d][l+1][r] = max(dp[u][d][l+1][r], dp[u][d][l][r] + cs.getSum(y1, ex - 1 - l, y2, ex - 1 - l));
                    if(ex + 1 + r <= w - 1 - l)
                        dp[u][d][l][r+1] = max(dp[u][d][l][r+1], dp[u][d][l][r] + cs.getSum(y1, ex + 1 + r, y2, ex + 1 + r));

                    int x1 = max(ex - l, r);
                    int x2 = min(ex + r, w - 1 - l);
                    if(ey - 1 - u >= d)
                        dp[u+1][d][l][r] = max(dp[u+1][d][l][r], dp[u][d][l][r] + cs.getSum(ey - 1 - u, x1, ey - 1 - u, x2));
                    if(ey + 1 + d <= h - 1 - u)
                        dp[u][d+1][l][r] = max(dp[u][d+1][l][r], dp[u][d][l][r] + cs.getSum(ey + 1 + d, x1, ey + 1 + d, x2));
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}