/*
LANG:C++
TASK:hop
*/
#include <iostream>
#include <queue>
using namespace std;
int N,M;
int x1,x2,y1,y2,s1,s2;
int d[1501][1501];
bool u[1501][1501];
bool u1[1501][1501];
int x[9]={0,-1,-1,-1,0,0,1,1,1};
int y[9]={0,-1,0,1,-1,1,-1,0,1};
struct A{
	int i,j;};
queue <A> q;

/*void bfs(int i,int j,int s)
{
	memset(u,0,sizeof(u));
	A h;
	h.i=i;
	h.j=j;
		q.push(h);
		u[h.i][h.j]=1;
		while(!q.empty())
			{
				A v;
				v=q.front();
			//	cout<<v.i<<" "<<v.j<<endl;
				int k;
				for(k=1;k<=8;k++)
				{
				A h;
				h=v;
				h.i+=(s*x[k]);
				h.j+=(s*y[k]);
					if(h.i>=0&&h.i<=N&&h.j>=0&&h.j<=M&&!u[h.i][h.j])
						{
							d[h.i][h.j]+=(d[v.i][v.j]+1);
							u[h.i][h.j]=1;
							q.push(h);
						}
				}			
			q.pop();
			}	
													 
}





void bfs1(int i,int j,int s)
{
	memset(u1,0,sizeof(u1));
	A h;
	h.i=i;
	h.j=j;
		q.push(h);
		u1[h.i][h.j]=1;
		while(!q.empty())
			{
				A v;
				v=q.front();
			//	cout<<v.i<<" "<<v.j<<endl;
				int k;
				for(k=1;k<=8;k++)
				{
				A h;
				h=v;
				h.i+=(s*x[k]);
				h.j+=(s*y[k]);
					if(h.i>=0&&h.i<=N&&h.j>=0&&h.j<=M&&!u1[h.i][h.j])
						{
							d[h.i][h.j]+=(d[v.i][v.j]+1);
							u1[h.i][h.j]=1;
							q.push(h);
						}
				}			
			q.pop();
			}	
													 
}
*/




void bfs(int i,int j,int s)
{
	memset(u,0,sizeof(u));
	A h;
	h.i=i;
	h.j=j;
		q.push(h);
		u[h.i][h.j]=1;
		while(!q.empty())
			{
				A v;
				v=q.front();
			//	cout<<v.i<<" "<<v.j<<endl;
				int k,l,m,n;	
				int lvl1,lvl2;
				k=v.i-s;
				l=v.j-s;
				m=v.i+s;
				n=v.j+s;
				A h;
					for(lvl1=k;lvl1<=m;lvl1++)
						{
							for(lvl2=l;lvl2<=n;lvl2++)
								{
									if(lvl1<0||lvl1>N||lvl2<0||lvl2>M) continue;
									
									if((lvl1-v.i)*(lvl1-v.i)+(lvl2-v.j)*(lvl2-v.j)==s*s&&!u[lvl1][lvl2])
										{
											u[lvl1][lvl2]=1;
											h.i=lvl1;
											h.j=lvl2;
											d[lvl1][lvl2]=(d[v.i][v.j]+1);
											q.push(h);
										}
								}
						}	
			q.pop();
			}	
													 
}




void bfs1(int i,int j,int s)
{
	memset(u1,0,sizeof(u1));
	A h;
	h.i=i;
	h.j=j;
		q.push(h);
		u1[h.i][h.j]=1;
		while(!q.empty())
			{
				A v;
				v=q.front();
			//	cout<<v.i<<" "<<v.j<<endl;
				int k,l,m,n;	
				int lvl1,lvl2;
				k=v.i-s;
				l=v.j-s;
				m=v.i+s;
				n=v.j+s;
				A h;
					for(lvl1=k;lvl1<=m;lvl1++)
						{
							for(lvl2=l;lvl2<=n;lvl2++)
								{
									if(lvl1<0||lvl1>N||lvl2<0||lvl2>M) continue;
										
									if((lvl1-v.i)*(lvl1-v.i)+(lvl2-v.j)*(lvl2-v.j)==s*s&&!u1[lvl1][lvl2])
										{
										//	cout<<lvl1<<" "<<lvl2<<" "<<v.i<<" "<<v.j<<endl;
											u1[lvl1][lvl2]=1;
											h.i=lvl1;
											h.j=lvl2;
											d[lvl1][lvl2]=(d[v.i][v.j]+1);
											q.push(h);
										}
								}
						}	
			q.pop();
			}	
													 
}


int main()
{
//	freopen("hop.txt","r",stdin);
//	freopen("hop1.txt","w",stdout);
	cin>>N>>M;
	cin>>x1>>y1>>s1;
	cin>>x2>>y2>>s2;
//	cout<<N<<" "<<M<<endl;
	memset(d,0,sizeof(d));
	bfs(x1,y1,s1);
	bfs1(x2,y2,s2);
		int i,j;
	int mini=99999999;	
			for(i=0;i<=N;i++)
				for(j=0;j<=M;j++)
					{
						if(u[i][j]&&u1[i][j])
						{
							cout<<d[i][j]<<" "<<i<<" "<<j<<endl;
						mini=min(d[i][j],mini);
						}
					}
		cout<<mini<<endl;			
}
	
	
