// Copyright (C) 2016 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <cassert>
#include <ctime>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <string>

#define x first
#define y second
#define MP std::make_pair
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

typedef long long LL;
typedef std::pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

inline bool chkmax(short &a, short b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
std::string procStatus()
{
    std::ifstream t("/proc/self/status");
    return std::string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        if (ch == '-')
            f = -1;
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 105;

int N, M, X, Y;
int A[MAXN][MAXN];
int tot;

void input()
{
    read(N); read(M);
    for (int i = 1; i <= N; ++i) {
        static char s[MAXN];
        scanf("%s", s);
        for (int j = 1; j <= M; ++j) {
            if (s[j - 1] == '.')
                A[i][j] = 0;
            else if (s[j - 1] == 'E') {
                A[i][j] = 0;
                X = i;
                Y = j;
            } else {
                A[i][j] = 1;
            }
        }
    }
}

void solve()
{
    static short hsum[MAXN][MAXN], vsum[MAXN][MAXN];

    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= M; ++j) {
            hsum[i][j] = hsum[i][j - 1] + A[i][j];
            vsum[i][j] = vsum[i - 1][j] + A[i][j];
        }
    }

    static short dp[MAXN][MAXN][MAXN][MAXN];
    short ans = 0;

    for (int u = 0; X + u <= N; ++u) {
        for (int d = 0; X - d >= 1; ++d) {
            for (int l = 0; Y + l <= M; ++l) {
                for (int r = 0; Y - r >= 1; ++r) {
                    chkmax(ans, dp[u][d][l][r]);
                    if (X + u + 1 <= N - d) chkmax(dp[u + 1][d][l][r], dp[u][d][l][r] + hsum[X + u + 1][std::min(Y + l, M - r)] - hsum[X + u + 1][std::max(Y - r, 1 + l) - 1]);
                    if (X - d - 1 >= 1 + u) chkmax(dp[u][d + 1][l][r], dp[u][d][l][r] + hsum[X - d - 1][std::min(Y + l, M - r)] - hsum[X - d - 1][std::max(Y - r, 1 + l) - 1]);
                    if (Y + l + 1 <= M - r) chkmax(dp[u][d][l + 1][r], dp[u][d][l][r] + vsum[std::min(X + u, N - d)][Y + l + 1] - vsum[std::max(X - d, 1 + u) - 1][Y + l + 1]);
                    if (Y - r - 1 >= 1 + l) chkmax(dp[u][d][l][r + 1], dp[u][d][l][r] + vsum[std::min(X + u, N - d)][Y - r - 1] - vsum[std::max(X - d, 1 + u) - 1][Y - r - 1]);
                }
            }
        }
    }

    printf("%d\n", (int)ans);
}

int main()
{
    input();
    solve();

    // std::cout << procStatus();

    return 0;
}


Measured memory_bytes: 205184