#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<cassert>
#define N 510
#define M 8000000
#define oo 0x3f3f3f3f
using namespace std;

struct node
{
    int x,y;

    node (){}
    node (int a,int b):x(a),y(b){}
};

queue<node>que;
queue<int>que1;
vector<node>vec[N*N];
char map[N][N],mark[N*N];
int color[N][N],cntC;
int first[N],next[N*N*8],end[N*N*8],cnt_edge;
int d[2][N*N],step[N][N];
int mx[8]={1,-1,0,0,1,1,-1,-1},my[8]={0,0,1,-1,1,-1,1,-1};
int n,m;

void addEdge(int u,int v)
{
	end[cnt_edge]=v;
	next[cnt_edge]=first[u];
	first[u]=cnt_edge++;
}

void dfs(int x,int y)
{
	int i,nx,ny;

	color[x][y]=cntC;
	vec[cntC].push_back(node(x,y));

	for (i=0;i<8;i++)
	{
		nx=x+mx[i];
		ny=y+my[i];

		if (nx>=0&&nx<n&&ny>=0&&ny<m&&map[nx][ny]==map[x][y]&&color[nx][ny]==0)
			dfs(nx,ny);
	}
}

void bfs1(int st,int dis[])
{
	int u,v,i;

	memset(mark,0,sizeof(mark));
	for (i=1;i<=cntC;i++)
		dis[i]=oo;
	dis[st]=0;
	mark[st]=1;
	que1.push(st);
	while (!que1.empty())
	{
		u=que1.front();
		que1.pop();

		for (i=first[u];i;i=next[i])
		{
			v=end[i];
			if (mark[v]==0)
			{
				dis[v]=dis[u]+1;
				mark[v]=1;
				que1.push(v);
			}
		}
	}
}

void bfs(node st)
{
	node u,v;
	int i;

	memset(step,0,sizeof(step));
	step[st.x][st.y]=1;
	que.push(st);

	while (!que.empty())
	{
		u=que.front();
		que.pop();

		for (i=0;i<8;i++)
		{
			v.x=u.x+mx[i];
			v.y=u.y+my[i];

			if (v.x>=0&&v.x<n&&v.y>=0&&v.y<m&&map[v.x][v.y]!='0'&&
				step[v.x][v.y]==0&&d[0][color[v.x][v.y]]<=d[0][color[u.x][u.y]])
			{
				step[v.x][v.y]=step[u.x][u.y]+1;
				que.push(v);
			}
		}
	}
}


int main()
{
    int i,j,k,x,y,nx,ny,ans_d,ans_s;
    node st,en;

    scanf("%d%d",&n,&m);
    scanf("%d%d%d%d",&st.x,&st.y,&en.x,&en.y);
    st.x--;
    st.y--;
    en.x--;
    en.y--;

    for (i=0;i<n;i++)
       scanf("%s",map[i]);

	memset(color,0,sizeof(color));
	cntC=0;
	for (i=0;i<n;i++)
		for (j=0;j<m;j++)
			if (color[i][j]==0&&map[i][j]!='0')
			{
				cntC++;
				dfs(i,j);
			}

	memset(first,0,sizeof(first));
	cnt_edge=1;
	for (i=0;i<n;i++)
		for (j=0;j<m;j++)
			if (color[i][j])
			{
				for (k=0;k<8;k++)
				{
					x=i+mx[k];
					y=j+my[k];

					if (x>=0&&x<n&&y>=0&&y<m&&color[x][y]!=color[i][j]&&color[x][y]!=0)
						addEdge(color[i][j],color[x][y]);
				}
			}

	bfs1(color[st.x][st.y],d[0]);
	//bfs1(color[en.x][en.y],d[1]);
	ans_d=d[0][color[en.x][en.y]];
	if (ans_d==oo)
	{
		printf("0 0\n");
		return 0;
	}

	/*
	memset(map,0,sizeof(map));
	for (i=1;i<=cntC;i++)
		if (d[0][i]+d[1][i]==ans_d)
		{
			for (j=0;j<vec[i].size();j++)
				map[vec[i][j].x][vec[i][j].y]=1;
		}
	*/

	bfs(en);
	ans_s=step[st.x][st.y];
	//assert(ans_s>0);

	printf("%d %d\n",ans_s,ans_d);

    return 0;
}