#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

const int maxn = 105;
int n, m, sx, sy;
string a[maxn];
int pr[maxn][maxn];

int d[2][maxn][maxn][maxn];

void uax(int &a, int b) {
    a = max(a, b);
}

int get(int xl, int xr, int yl, int yr) {
    if (xl >= xr || yl >= yr)
        return 0;
    return pr[xr][yr] + pr[xl][yl] - pr[xr][yl] - pr[xl][yr];
}

int main() {
    #ifdef LOCAL
    assert(freopen("e.in", "r", stdin));
    #else
    #endif
    cin >> n >> m;
    forn (i, n) {
        cin >> a[i];
        forn (j, m)
            if (a[i][j] == 'E')
                sx = i, sy = j;
    }
    forn (i, n)
        forn (j, m)
            pr[i + 1][j + 1] = (a[i][j] == 'o') + pr[i + 1][j] + pr[i][j + 1] - pr[i][j];
    
    forn (qq, 2)
        forn (i, maxn)
            forn (j, maxn)
                forn (k, maxn)
                    d[qq][i][j][k] = -inf;
    int q = 0;
    d[q][sx + 1][sy][sy + 1] = 0;
    for (int xl = sx; xl >= 0; --xl) {
        for (int xr = xl + 1; xr <= n; ++xr)
            for (int ylen = 1; ylen <= m; ++ylen)
                for (int yl = 0; yl + ylen <= m; ++yl) {
                    int yr = yl + ylen;
                    d[q ^ 1][xr][yl][yr] = -inf;
                }

        for (int xr = xl + 1; xr <= n; ++xr) {
            for (int ylen = 1; ylen <= m; ++ylen) {
                for (int yl = 0; yl + ylen <= m; ++yl) {
                    int yr = yl + ylen;
                    if (d[q][xr][yl][yr] < 0)
                        continue;
                    int val = d[q][xr][yl][yr];

                    int XL = xr - sx - 1;
                    int XR = xl - sx + n;
                    int YL = yr - sy - 1;
                    int YR = yl - sy + m;
                    //cerr << xl << ' ' << xr << ' ' << yl << ' ' << yr << ": " << val << '\n';
                    //cerr << XL << ' ' << XR << ' ' << YL << ' ' << YR << '\n';

                    //xr++
                    if (xr < n) {
                        int add = 0;
                        if (XR > xr)
                            add = get(xr, xr + 1, max(yl, YL), min(yr, YR));
                        uax(d[q][xr + 1][yl][yr], val + add);
                    }

                    //xl--
                    if (xl > 0) {
                        int add = 0;
                        if (XL < xl)
                            add = get(xl - 1, xl, max(yl, YL), min(yr, YR));
                        uax(d[q ^ 1][xr][yl][yr], val + add);
                    }

                    //yr++
                    if (yr < m) {
                        int add = 0;
                        if (YR > yr)
                            add = get(max(xl, XL), min(xr, XR), yr, yr + 1);
                        uax(d[q][xr][yl][yr + 1], val + add);
                    }

                    //yl--
                    if (yl > 0) {
                        int add = 0;
                        if (YL < yl)
                            add = get(max(xl, XL), min(xr, XR), yl - 1, yl);
                        uax(d[q][xr][yl - 1][yr], val + add);
                    }
                }
            }
        }

        q ^= 1;
    }
    q ^= 1;
    cout << d[q][n][0][m] << '\n';
}

Measured memory_bytes: 9344