#include <bits/stdc++.h>

using namespace std;

//#define FILE_IO

int N, M, X, Y;
int s[105][105];
char a[105][105];

struct state
{
    int u = 0, d = 0, l = 0, r = 0;
    state() { ; }
    state(int _u, int _d, int _l, int _r) { u = _u, d = _d, l = _l, r = _r; }

    const bool operator< (const state& st) const
    {
        if(u == st.u)
        {
            if(d == st.d)
            {
                if(l == st.l)   return r < st.r;
                return l < st.l;
            }
            return d < st.d;
        }
        return u < st.u;
    }
};

queue<state> q;
int mp[50][50][100][100];
bitset<100> is[50][50][100];

int getsum(int xs, int ys, int xf, int yf)
{
    if(xs > xf || ys > yf)  return 0;
    xs = max(xs, 1); ys = max(ys, 1);
    xf = min(xf, N); yf = min(yf, M);
    return s[xf][yf] - s[xs - 1][yf] - s[xf][ys - 1] + s[xs - 1][ys - 1];
}

bool count(state st)
{
    if(is[st.u][st.l][st.d][st.r])  return true;
    is[st.u][st.l][st.d][st.r] = 1;
    return false;
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d\n", &N, &M);
    for(int i = 1; i <= N; i++)
        scanf("%s\n", a[i] + 1);

    for(int i = 1; i <= N; i++)
        for(int j = 1; j <= M; j++)
        {
            s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + (a[i][j] == 'o');
            if(a[i][j] == 'E') { X = i, Y = j; }
        }

    if(X > N / 2)
    {
        for(int i = 1; i <= N; i++)
            if(i < N - i + 1)
                for(int j = 1; j <= M; j++)
                    swap(a[i][j], a[N - i + 1][j]);
        for(int i = 1; i <= N; i++)
            for(int j = 1; j <= M; j++)
            {
                s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + (a[i][j] == 'o');
                if(a[i][j] == 'E') { X = i, Y = j; }
            }
    }

    if(Y > M / 2)
    {
        for(int j = 1; j <= M; j++)
            if(j < M - j + 1)
                for(int i = 1; i <= N; i++)
                    swap(a[i][j], a[i][M - j + 1]);

        for(int i = 1; i <= N; i++)
            for(int j = 1; j <= M; j++)
            {
                s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + (a[i][j] == 'o');
                if(a[i][j] == 'E') { X = i, Y = j; }
            }
    }

    int ans = 0;
    q.push(state());

    while(!q.empty())
    {
        auto st = q.front();
        q.pop();

        int val = mp[st.u][st.l][st.d][st.r];
        ans = max(ans, val);
        int xs, ys, xf, yf;
        xs = st.d + 1, xf = N - st.u;
        ys = st.r + 1, yf = M - st.l;

        if(xs > xf || ys > yf)  continue;

        if(X - st.u - 1 >= xs)
        {
            st.u++;
            if(!count(st))   q.push(st);
            mp[st.u][st.l][st.d][st.r] = max(mp[st.u][st.l][st.d][st.r], val + getsum(X - st.u, max(Y - st.l, ys), X - st.u, min(Y + st.r, yf)));
            st.u--;
        }

        if(X + st.d + 1 <= xf)
        {
            st.d++;
            if(!count(st))   q.push(st);
            mp[st.u][st.l][st.d][st.r] = max(mp[st.u][st.l][st.d][st.r], val + getsum(X + st.d,  max(Y - st.l, ys), X + st.d, min(Y + st.r, yf)));
            st.d--;
        }

        if(Y - st.l - 1 >= ys)
        {
            st.l++;
            if(!count(st))   q.push(st);
            mp[st.u][st.l][st.d][st.r] = max(mp[st.u][st.l][st.d][st.r], val + getsum(max(X - st.u, xs), Y - st.l, min(X + st.d, xf), Y - st.l));
            st.l--;
        }

        if(Y + st.r + 1 <= yf)
        {
            st.r++;
            if(!count(st))   q.push(st);
            mp[st.u][st.l][st.d][st.r] = max(mp[st.u][st.l][st.d][st.r], val + getsum(max(X - st.u, xs), Y + st.r, min(X + st.d, xf), Y + st.r));
            st.r--;
        }
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 101376