#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

int n, m;
string s[110];

int rsum[110][110];
int csum[110][110];

int dp[110][110];

int sy, sx;

void fy(){
  REP( i , n/2 ){
    swap( s[i] , s[n-1-i] );
  }
}
void fx(){
  REP( j , m/2 ){
    REP( i , n ){
      swap( s[i][j] , s[i][m-1-j] );
    }
  }
}

int main(){

  n = in();
  m = in();
  REP( i , n ){
    s[i] = stin();
  }

  REP( i , n ){
    REP( j , m ){
      if( s[i][j] == 'E' ){
	sy = i;
	sx = j;
      }
    }
  }

  if( sy >= n / 2 ){
    fy();
  }
  if( sx >= m / 2 ){
    fx();
  }

  REP( i , n ){
    REP( j , m ){
      if( s[i][j] == 'E' ){
	sy = i;
	sx = j;
	s[i][j] = '.';
      }
    }
  }

  assert( sy <= n/2 );
  assert( sx <= m/2 );

  /*
  REP( i , n ){
    cout << s[i] << endl;
  }
  cout << sy << " " << sx << endl;
  */
  
  REP( i , n ){
    REP( j , m ){
      rsum[i][j+1] = rsum[i][j];
      csum[i+1][j] = csum[i][j];      
      if( s[i][j] == 'o' ){
	rsum[i][j+1]++;
	csum[i+1][j]++;
      }
    }
  }

  int ans = 0;
  REP( i , sy+1 ){
    REP( j , sx+1 ){
      int res = 0;
      REP( k , sy+1 ){
	REP( l , sx+1 ){
	  if( s[i+k][j+l] == 'o' ){
	    res++; 
	  }
	}
      }
      int ay = sy + i;
      int ax = sx + j;
      REP( k , n+1 ){
	REP( l , m+1 ){
	  dp[k][l] = 0;
	}
      }
      dp[ay][ax] = res;
      FOR( k , ay , n - sy + i ){
	FOR( l , ax , m - sx + j ){
	  // cout << k << " " << l << " " << dp[k][l] << endl;
	  chmax( dp[k+1][l] , dp[k][l] + rsum[k+1][l+1] - rsum[k+1][l-sx] );
	  chmax( dp[k][l+1] , dp[k][l] + csum[k+1][l+1] - csum[k-sy][l+1] );
	}
      }
      // cout << i << " " << j << endl;
      // cout << n - sy + i - 1 << " " << m - sx + j - 1 << endl;
      chmax( ans , dp[n-sy+i-1][m-sx+j-1] );
    }
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 384