Problem: We have a grid with H rows and W columns. The state of the cell at the i-th (1≤i≤H) row and j-th (1≤j≤W) column is represented by a letter a_{ij}, as follows:

* `.` : This cell is empty.
* `o` : This cell contains a robot.
* `E` : This cell contains the exit. `E` occurs exactly once in the whole grid.



Snuke is trying to salvage as many robots as possible, by performing the following operation some number of times:

* Select one of the following directions: up, down, left, right. All remaining robots will move one cell in the selected direction, except when a robot would step outside the grid, in which case the robot will explode and immediately disappear from the grid. If a robot moves to the cell that contains the exit, the robot will be salvaged and immediately removed from the grid.



Find the maximum number of robots that can be salvaged.

Constraints

* 2≤H,W≤100
* a_{ij} is `.`, `o` or `E`.
* `E` occurs exactly once in the whole grid.

Input

The input is given from Standard Input in the following format:


H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}


Output

Print the maximum number of robots that can be salvaged.

Examples

Input

3 3
o.o
.Eo
ooo


Output

3


Input

2 2
E.
..


Output

0


Input

3 4
o...
o...
oooE


Output

5


Input

5 11
ooo.ooo.ooo
o.o.o...o..
ooo.oE..o..
o.o.o.o.o..
o.o.ooo.ooo


Output

12

Solution (in CPP):

Solution:
#include <cstdio>
#include <cstring>
#include <stack>
#include <vector>
#define MAXN 110
#define MAXS 5100
using namespace std;

int n,m;
int a[MAXN][MAXN],s[MAXN][MAXN],ex,ey;
int px[MAXN][MAXN],py[MAXN][MAXN],numpx,numpy;
int f[MAXS][MAXS];

int getS(int x1,int x2,int y1,int y2){
	return s[x2][y2]-s[x1-1][y2]-s[x2][y1-1]+s[x1-1][y1-1];
}

int trans(int x1,int x2,int y1,int y2,int x3,int x4,int y3,int y4){
	int tx1=x2-n+ex,tx2=x1+ex-1;
	int ty1=y2-m+ey,ty2=y1+ey-1;
	if(tx1>x3) x3=tx1;
	if(tx2<x4) x4=tx2;
	if(ty1>y3) y3=ty1;
	if(ty2<y4) y4=ty2;
	if(x3<=x4 && y3<=y4) return getS(x3,x4,y3,y4);
	else return 0;
}

int gao(int x1,int x2,int y1,int y2){
	if(x1==x2 && y1==y2) return a[x1][y1];
	int res=0;
	if(x1<x2){
		res=max(res,f[px[x1][x2-1]][py[y1][y2]]+trans(x1,x2-1,y1,y2,x2,x2,y1,y2));
		res=max(res,f[px[x1+1][x2]][py[y1][y2]]+trans(x1+1,x2,y1,y2,x1,x1,y1,y2));
	}
	if(y1<y2){
		res=max(res,f[px[x1][x2]][py[y1][y2-1]]+trans(x1,x2,y1,y2-1,x1,x2,y2,y2));
		res=max(res,f[px[x1][x2]][py[y1+1][y2]]+trans(x1,x2,y1+1,y2,x1,x2,y1,y1));
	}
	return res;
}

int main(){
#ifdef DEBUG
	freopen("E.in","r",stdin);
#endif
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		static char str[MAXN];
		scanf("%s",str+1);
		for(int j=1;j<=m;j++)
			if(str[j]=='o'){
				a[i][j]=1;
			}else if(str[j]=='E'){
				ex=i;
				ey=j;
			}
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) 
			s[i][j]=a[i][j]+s[i-1][j]+s[i][j-1]-s[i-1][j-1];
	for(int i=1;i<=n;i++)
		for(int j=i;j<=n;j++)
			px[i][j]=++numpx;
	for(int i=1;i<=m;i++)
		for(int j=i;j<=m;j++)
			py[i][j]=++numpy;
	for(int w=1;w<=n;w++)
		for(int h=1;h<=m;h++)
			for(int i=1;i+w-1<=n;i++)
				for(int j=1;j+h-1<=m;j++)
					f[px[i][i+w-1]][py[j][j+h-1]]=gao(i,i+w-1,j,j+h-1);
	printf("%d\n",f[px[1][n]][py[1][m]]);
	return 0;
}