#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
 
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
const int N = 101;
short dp[N][N][N][N];

int has[N][N];
int cnti[N][N];
int cntj[N][N];

int main(){
    fastIO;
    int n, m;
    cin >> n >> m;
    char f;
    int ei, ej;
    for(int i = 1; i <= n; i ++ ){
        for(int j = 1 ;j  <= m ; j ++ ){
            cin >> f;
            if(f == 'E')
                ei = i, ej = j;
            has[i][j] = 0;
            if(f == 'o')
                has[i][j] = 1;
        }
    }
    for(int i = 1 ; i <= n; i ++ ){
        for(int j = 1; j <= m ; j ++ ){
            cnti[i][j] = has[i][j] + cnti[i][j-1];
            cntj[i][j] = has[i][j] + cntj[i-1][j];
        }
    }
    short res = 0;
    short cur;
    int ln;
    short extra;
    int lf, rf;
    for(int u = 0 ; u < n; u ++ ){ // max u and lower u banned
        for(int d = 0 ; d < n; d ++ ){ // max d and upper d banned
            for(int l = 0 ; l < m; l ++ ){ // max l and right l banned
                for(int r = 0; r < m ; r ++ ){ // max r and left r banned
                    if(u + d >= n) continue;
                    if(l + r >= m) continue;
                    if(ei - u <= 0) continue;
                    if(ei + d > n) continue;
                    if(ej - l <= 0) continue;
                    if(ej + r > m) continue;
                    cur = dp[u][d][l][r];
                    res = max(res, cur);
                    if(ei - u - 1 >= 1){
                        ln = ei - u - 1;
                        extra = 0;
                        if(d < ln){
                            lf = max(r + 1, ej - l);
                            rf = min(m - l, ej + r);
                            if(lf <= rf)
                                extra = cnti[ln][rf] - cnti[ln][lf - 1];
                        }
                        dp[u + 1][d][l][r] = max(dp[u + 1][d][l][r], short(cur + extra));
                    }
                    
                    if(ei + d + 1 <= n){
                        ln = ei + d + 1;
                        extra = 0;
                        if(ln <= n - u){
                            lf = max(r + 1, ej - l);
                            rf = min(m - l, ej + r);
                            if(lf <= rf)
                                extra = cnti[ln][rf] - cnti[ln][lf - 1];
                        }
                        dp[u][d + 1][l][r] = max(dp[u][d + 1][l][r], short(cur + extra));
                    }
                
                    if(ej - l - 1 >= 1){
                        ln = ej - l - 1;
                        extra = 0;
                
                        if(ln > r){
                            lf = max(d + 1, ei - u);
                            rf = min(n - u, ei + d);
                            if(lf <= rf)
                                extra = cntj[rf][ln] - cntj[lf - 1][ln];
                        }

                        dp[u][d][l + 1][r] = max(dp[u][d][l + 1][r], short(cur + extra));
                    }
                    if(ej + r + 1 <= m){
                        ln = ej + r + 1;
                        extra = 0;
                        if(ln <= m - l){
                            lf = max(d + 1, ei - u);
                            rf = min(n - u, ei + d);
                            if(lf <= rf)
                                extra = cntj[rf][ln] - cntj[lf - 1][ln]; 
                        }
                        dp[u][d][l][r + 1] = max(dp[u][d][l][r + 1], short(cur + extra));
                    }
                    
                    
                }
            }
        }
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 199040