#include <cstdio>
#include <iostream>
#define ri register int
using namespace std;
 
typedef long long LL;
const int N = 102;

char ch[N][N];
short le[N][N], up[N][N], dp[N][N][N][N];
 
inline void upd(short &x, short y) {
  if (x < y) x = y;
}
 
int main() {
  int n, m, ex, ey;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i ++) {
    scanf("%s", ch[i] + 1);
    for (int j = 1; j <= m; j ++) {
      le[i][j] = le[i][j - 1];
      up[i][j] = up[i - 1][j];
      if (ch[i][j] == 'o') le[i][j] ++, up[i][j] ++;
      if (ch[i][j] == 'E') ex = i, ey = j;
    }
  }
  short t, ans = 0;
  for (ri U = ex; U; U --)
    for (ri D = ex; D <= n; D ++)
      for (ri L = ey; L; L --)
	for (ri R = ey; R <= m; R ++) {
	  t = dp[U][D][L][R];
	  ans = max(ans, t);
	  if (U - 1 > D - ex) upd(dp[U - 1][D][L][R], t + le[U - 1][min(R, m - (ey - L))] - le[U - 1][max(L - 1, R - ey)]);
	  if (n - D > ex - U) upd(dp[U][D + 1][L][R], t + le[D + 1][min(R, m - (ey - L))] - le[D + 1][max(L - 1, R - ey)]);
	  if (L - 1 > R - ey) upd(dp[U][D][L - 1][R], t + up[min(D, n - (ex - U))][L - 1] - up[max(U - 1, D - ex)][L - 1]);
	  if (m - R > ey - L) upd(dp[U][D][L][R + 1], t + up[min(D, n - (ex - U))][R + 1] - up[max(U - 1, D - ex)][R + 1]);
	}
  cout << ans << endl;
  return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define LL long long
using namespace std;
const int N=200005;
const LL inf=1ll<<40;
int n,q,sta,stb;
int x[N];
struct tree
{
	LL mv1[N*4],mv2[N*4],tag[N*4];//mv1-> f[x]-x mv2 -> f[x]+x
	void pushup(int k)
	{
		mv1[k]=min(mv1[k<<1],mv1[k<<1|1]);
		mv2[k]=min(mv2[k<<1],mv2[k<<1|1]);
	}
	void setv(int k,LL v){tag[k]+=v;mv1[k]+=v;mv2[k]+=v;}
	void pushdown(int k)
	{
		if(!tag[k])return;
		setv(k<<1,tag[k]);setv(k<<1|1,tag[k]);
		tag[k]=0;
	}
	void build(int k,int l,int r)
	{
		tag[k]=0;
		if(l==r){mv1[k]=mv2[k]=inf;return;}
		int mid=(l+r)>>1;
		build(k<<1,l,mid);build(k<<1|1,mid+1,r);
		pushup(k);
	}
	void upd(int k,int l,int r,int pos,LL v)
	{
		if(l==r){if(v<mv1[k]+l){mv1[k]=v-l;mv2[k]=v+l;}return;}
		int mid=(l+r)>>1;
		pushdown(k);
		if(mid>=pos)upd(k<<1,l,mid,pos,v);
		else upd(k<<1|1,mid+1,r,pos,v);
		pushup(k);
	}
	LL query1(int k,int l,int r,int ql,int qr)// query mv1
	{
		if((l>=ql&&r<=qr)||mv1[k]>=inf)return mv1[k];
		int mid=(l+r)>>1;LL res=inf;
		pushdown(k);
		if(mid>=ql)res=min(res,query1(k<<1,l,mid,ql,qr));
		if(mid<qr)res=min(res,query1(k<<1|1,mid+1,r,ql,qr));
		return res;
	}
	LL query2(int k,int l,int r,int ql,int qr)// query2 mv2
	{
		if((l>=ql&&r<=qr)||mv2[k]>=inf)return mv2[k];
		int mid=(l+r)>>1;LL res=inf;
		pushdown(k);
		if(mid>=ql)res=min(res,query2(k<<1,l,mid,ql,qr));
		if(mid<qr)res=min(res,query2(k<<1|1,mid+1,r,ql,qr));
		return res;
	}
	LL querya(int k,int l,int r)
	{
		if(l==r)return mv1[k]+l;
		int mid=(l+r)>>1;
		pushdown(k);
		return min(querya(k<<1,l,mid),querya(k<<1|1,mid+1,r));
	}
}t;
int Abs(int x){return x<0?-x:x;}
int input()
{
	int x=0,F=1;
	char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')F=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
	return x*F;
}
int main()
{
	cin>>n>>q>>sta>>stb;
	for(int i=1;i<=q;i++)x[i]=input();
	x[0]=sta;
	t.build(1,1,n);
	t.upd(1,1,n,stb,0);
	for(int i=1;i<=q;i++)
	{
		LL minv=min(t.query1(1,1,n,1,x[i])+x[i],t.query2(1,1,n,x[i]+1,n)-x[i]);
		t.setv(1,Abs(x[i]-x[i-1]));
		t.upd(1,1,n,x[i-1],minv);
	}
	cout<<t.querya(1,1,n);
	return 0;
}
