#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

int getSum(const vector<vector<int>>& sums,
           int x1, int y1,
           int x2, int y2) {
    if (x1 <= x2 && y1 <= y2) {
        return sums[x2][y2] - sums[x1 - 1][y2] - sums[x2][y1 - 1]
            + sums[x1 - 1][y1 - 1];
    } else {
        return 0;
    }
}

const int NMAX = 105;

int dp[2][NMAX][NMAX][NMAX];

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector<string> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }

    vector<vector<int>> sums(n + 2, vector<int>(m + 2, 0));
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            sums[i][j] = sums[i - 1][j] + sums[i][j - 1] - sums[i - 1][j - 1]
                + (A[i - 1][j - 1] == 'o');
        }
    }

    int ox = -1, oy = -1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (A[i - 1][j - 1] == 'E') {
                ox = i;
                oy = j;
                break;
            }
        }
    }

    int r1 = n - ox;
    int r2 = ox - 1;
    int c1 = m - oy;
    int c2 = oy - 1;
    for (int i = 0, u = 0; i <= r1; ++i, u ^= 1) {
        memset(dp[u ^ 1], 0, sizeof dp[u ^ 1]);
        for (int j = 0; j <= r2; ++j) {
            for (int k = 0; k <= c1; ++k) {
                for (int l = 0; l <= c2; ++l) {
                    if (i + 1 <= r1) {
                        int nval = 0;
                        if (ox + i + 1 <= n - j) {
                            nval = getSum(sums,
                                    ox + i + 1, max(k + 1, oy - l),
                                    ox + i + 1, min(m - l, oy + k));
                        }
                        nval += dp[u][j][k][l];
                        dp[u ^ 1][j][k][l] = max(dp[u ^ 1][j][k][l],
                                nval);
                    }
                    if (j + 1 <= r2) {
                        int nval = 0;
                        if (ox - j - 1 > i) {
                            nval = getSum(sums,
                                    ox - j - 1, max(k + 1, oy - l),
                                    ox - j - 1, min(m - l, oy + k));
                        }
                        nval += dp[u][j][k][l];
                        dp[u][j + 1][k][l] = max(dp[u][j + 1][k][l],
                                nval);
                    }
                    if (k + 1 <= c1) {
                        int nval = 0;
                        if (oy + k + 1 <= m - l) {
                            nval = getSum(sums,
                                    max(i + 1, ox - j), oy + k + 1,
                                    min(n - j, ox + i), oy + k + 1);
                        }
                        nval += dp[u][j][k][l];
                        dp[u][j][k + 1][l] = max(dp[u][j][k + 1][l],
                                nval);
                    }
                    if (l + 1 <= c2) {
                        int nval = 0;
                        if (oy - l - 1 > k) {
                            nval = getSum(sums,
                                    max(i + 1, ox - j), oy - l - 1,
                                    min(n - j, ox + i), oy - l - 1);
                        }
                        nval += dp[u][j][k][l];
                        dp[u][j][k][l + 1] = max(dp[u][j][k][l + 1],
                                nval);
                    }
                }
            }
        }
    }
    int ans = dp[r1 & 1][r2][c1][c2];
    cout << ans << '\n';
}

Measured memory_bytes: 9344