import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
*
* @author cteam049
*/
public class grasshop
{
protected int r;
protected int c;
protected int gr;
protected int gc;
protected int lr;
protected int lc;
protected int[][] field;
/**
* @param args the command line arguments
*/
public static void main
( String[] args
) {
grasshop program = new grasshop();
program.run();
}
protected void run()
{
try
{
for ( ;; )
{
this.r = this.nextInt();
this.c = this.nextInt();
this.gr = this.nextInt();
this.gc = this.nextInt();
this.lr = this.nextInt();
this.lc = this.nextInt();
this.field = new int[ this.r ][ this.c ];
this.field[ this.gr - 1 ][ this.gc - 1 ] = 1;
if ( this.gr == this.lr && this.gc == this.lc )
{
continue;
}
try
{
int num = 1;
while ( this.makeJumps( num++ ) );
System.
out.
println( "impossible" ); }
catch ( SuccessException e )
{
System.
out.
println( e.
value ); }
}
}
{
e.printStackTrace();
}
}
protected boolean makeJumps( int num ) throws SuccessException
{
boolean res = false;
for ( int i = 0; i < this.r; i++ )
{
for ( int j = 0; j < this.c; j++ )
{
if ( this.field[ i ][ j ] == num )
{
res = res | this.makeOneJump( i - 2, j - 1, num + 1 );
res = res | this.makeOneJump( i - 2, j + 1, num + 1 );
res = res | this.makeOneJump( i - 1, j + 2, num + 1 );
res = res | this.makeOneJump( i + 1, j + 2, num + 1 );
res = res | this.makeOneJump( i + 2, j + 1, num + 1 );
res = res | this.makeOneJump( i + 2, j - 1, num + 1 );
res = res | this.makeOneJump( i + 1, j - 2, num + 1 );
res = res | this.makeOneJump( i - 1, j - 2, num + 1 );
}
}
}
return res;
}
protected boolean makeOneJump( int r, int c, int num) throws SuccessException
{
if ( r < 0 || c < 0 || r >= this.r || c >= this.c || this.field[ r ][ c ] != 0 )
{
return false;
}
if ( r == this.lr - 1 && c == this.lc - 1 )
{
throw new SuccessException( num - 1 );
}
this.field[ r ][ c ] = num;
return true;
}
protected class SuccessException
extends Exception {
public int value;
public SuccessException( int value )
{
this.value = value;
}
}
/* INPUT READING */
{
while ( ! st.hasMoreTokens() )
{
}
return st.nextToken();
}
{
return Integer.
parseInt( this.
nextToken() ); }
{
return input.readLine();
}
}