#include <cstdio>
#include <algorithm>
int N, M, X, Y, a[100][100], sx[100][100], sy[100][100], f[100][100][100][100];
inline int SY(int x, int l, int r)
{
	int L = std::max(l, r - Y), R = std::min(r, M - 1 - Y + l);
	return L > R ? 0 : sy[x][R] - (L ? sy[x][L - 1] : 0);
}
inline int SX(int y, int l, int r)
{
	int L = std::max(l, r - X), R = std::min(r, N - 1 - X + l);
	return L > R ? 0 : sx[R][y] - (L ? sx[L - 1][y] : 0);
}
int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; i++)
	{
		static char _i[101];
		scanf("%s", _i);
		for (int j = 0; j < M; j++)
			if (_i[j] == 'E')
				X = i, Y = j;
			else if (_i[j] == 'o')
				a[i][j] = 1;
	}
	for (int i = 0; i < N; i++)
		std::copy(a[i], a[i] + M, sx[i]);
	for (int i = 1; i < N; i++)
		for (int j = 0; j < M; j++)
			sx[i][j] += sx[i - 1][j];
	for (int i = 0; i < N; i++)
		std::copy(a[i], a[i] + M, sy[i]);
	for (int i = 0; i < N; i++)
		for (int j = 1; j < M; j++)
			sy[i][j] += sy[i][j - 1];
	for (int i = 0; i <= X; i++)
		for (int j = N - 1; j >= X; j--)
			for (int k = 0; k <= Y; k++)
				for (int l = M - 1; l >= Y; l--)
				{
					if (i > j - X)
						f[i][j][k][l] = std::max(f[i][j][k][l], f[i - 1][j][k][l] + SY(i - 1, k, l));
					if (j < N - 1 - X + i)
						f[i][j][k][l] = std::max(f[i][j][k][l], f[i][j + 1][k][l] + SY(j + 1, k, l));
					if (k > l - Y)
						f[i][j][k][l] = std::max(f[i][j][k][l], f[i][j][k - 1][l] + SX(k - 1, i, j));
					if (l < M - 1 - Y + k)
						f[i][j][k][l] = std::max(f[i][j][k][l], f[i][j][k][l + 1] + SX(l + 1, i, j));
				}
	printf("%d\n", f[X][X][Y][Y]);
	return 0;
}
