#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <deque>
#include <queue>
#include <cstring>
#include <set>
#include <list>
#include <map>
#include <random>
#include <unordered_map>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<bool> vb;
typedef std::vector<string> vs;
typedef std::vector<double> vd;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<int> > vvi;
typedef vector<vvi> vvvi;
typedef vector<vll> vvll;
typedef std::vector<std::pair<int, int> > vpi;
typedef vector<vpi> vvpi;
typedef std::pair<int, int> pi;
typedef std::pair<ll, ll> pll;
typedef std::vector<pll> vpll;

const long long mod = 1000000007;

#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define forn(i, a, b) for(int i = a; i < b; i++)

#define pb push_back
#define mp make_pair

int main()
{

    int h,w;
    scanf("%d %d\n", &h, &w);
    vs a(h);
    forn(i,0,h) getline(cin, a[i]);
    int x,y;
    forn(i,0,h) {
        forn(j,0,w) {
            if(a[i][j] == 'E') {
                y=i;
                x=j;
            }
        }
    }
    int l = x;
    int r = w-1-x;
    int u = y;
    int dw = h-1-y;
    vvi chr(h, vi(w,0));
    vvi chd(h, vi(w,0));
    forn(i,0,h) {
        forn(j,0,w) {
            if(i>0) chd[i][j] = chd[i-1][j];
            if(j>0) chr[i][j] = chr[i][j-1];
            if(a[i][j] == 'o') {
                chr[i][j]++;
                chd[i][j]++;
            }
        }
    }
    
    int ans = 0;
    vector<vvvi> d(l+1, vvvi(r+1, vvi(u+1, vi(dw+1, 0))));
    forn(il,0,l+1) {
        forn(ir, 0, r+1) {
            if(il+ir>=w) break;
            forn(iu, 0, u+1) {
                forn(id, 0, dw+1) {
                    if(id+iu >= h) break;
                    
                    if(l - il > ir) {
                        int bd = min(y+id, h-1-iu);
                        int bu = max(y-iu, id);
                        int upd = chd[bd][x-il-1];
                        if(bu>0) upd -= chd[bu-1][x-il-1];
                        d[il+1][ir][iu][id] = max(d[il+1][ir][iu][id], d[il][ir][iu][id] + upd);
                    }
                    if(r-ir>il) {
                        int bd = min(y+id, h-1-iu);
                        int bu = max(y-iu, id);
                        int upd = chd[bd][x+ir+1];
                        if(bu>0) upd -= chd[bu-1][x+ir+1];
                        d[il][ir+1][iu][id] = max(d[il][ir+1][iu][id], d[il][ir][iu][id] + upd);
                    }
                    if(iu +id< u) {
                        int br = min(x+ir, w-1-il);
                        int bl = max(x-il, ir);
                        int upd = chr[y-iu-1][br];
                        if(bl>0) upd-=chr[y-iu-1][bl-1];
                        d[il][ir][iu+1][id] = max(d[il][ir][iu+1][id], d[il][ir][iu][id] + upd);
                    }
                    if(id +iu< dw) {
                        int br = min(x+ir, w-1-il);
                        int bl = max(x-il, ir);
                        int upd = chr[y+id+1][br];
                        if(bl>0) upd-=chr[y+id+1][bl-1];
                        d[il][ir][iu][id+1] = max(d[il][ir][iu][id+1], d[il][ir][iu][id] + upd);
                    }
                    ans = max(ans,d[il][ir][iu][id]);
                }
            }
        }
    }
    cout<<ans;
    
    
}



Measured memory_bytes: 31616