#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = 1e6+10;
const int maxm = 55;
const LL MOD = 999999997;
inline LL read()
{
int c=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
c=c*10+ch-'0';
ch=getchar();
}
return c*f;
}
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
int Eular(int n)
{
int ret =1;
for(int i=2; i*i<=n; ++i)
{
if(n%i==0)
{
ret *= (i-1);
n/=i;
while(n%i==0)
{
ret*=i;
n/=i;
}
}
}
if(n>1) ret*=(n-1);
return ret;
}
int Get_divisor_sum(int n)
{
int sum=0;
for(int i=2; i*i<=n; ++i)
{
if(n%i==0)
{
sum+=i;
if(n/i!=i) sum+=n/i;
}
}
sum++;
return sum;
}
LL Quick_Mod(LL a,LL b,LL MOD)
{
LL ans=a,ret=1;
while(b)
{
if(b&1) ret = ret*ans%MOD;
b>>=1;
ans=ans*ans%MOD;
}
return ret;
}
char mapp[233][233];
int vis[233][233];
int n,m;
struct node
{
int x,y,dis;
};
int sx,sy,ex,ey;
int dir[8][2]= { 1,2,1,-2,2,1,2,-1,-1,2,-1,-2,-2,1,-2,-1};
bool okk(int x,int y)
{
if(x<n&&x>=0&&y>=0&&y<m)return true;
return false;
}
void bfs() // bfs
{
memset(vis,0,sizeof(vis));
queue<node> que;
node top= {sx,sy,0};
que.push(top);
int flag=0;
while(!que.empty())
{
node top=que.front();
que.pop();
if(top.x==ex && top.y==ey)//find the last position
{
if(top.dis==0) break;
printf("%d\n",top.dis);
flag=1;
break;
}
node vv;
for(int i=0; i<8; ++i)
{
vv.x=top.x+dir[i][0];
vv.y=top.y+dir[i][1];
int dx=top.x+dir[i][0]/2;
int dy=top.y+dir[i][1]/2;
if(mapp[dx][dy]=='#' ) continue; //“别马腿”,那么他将不能跳向有障碍物的左前和右前这两个方向。
if(okk(vv.x,vv.y) && mapp[vv.x][vv.y]!='#' && !vis[vv.x][vv.y])
{
vv.dis=top.dis+1;
que.push(vv);
vis[vv.x][vv.y]=1;
}
}
}
if(!flag) puts("-1"); //if no find
}
int main()
{
//freopen("1.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=0; i<n; ++i)
{
for(int j=0; j<m; ++j)
{
cin>>mapp[i][j];
if(mapp[i][j]=='s') //mark the first position
{
sx=i;
sy=j;
}
else if(mapp[i][j]=='e') //mark the last position
{
ex=i;
ey=j;
}
}
}
bfs();
}
return 0;
}