program jiji;
var f:text;
i,j,n,m,k,x1,x2,y1,y2,l,min,nr,ls,ld,lung,x,y:longint;
cx,cy:array[1..100000] of longint;
a,b:array[0..51,0..51] of longint;
gasit:boolean;
begin
assign(f,'kdrum.in');
reset(f);
readln(f,n,m,k);
readln(f,x1,y1,x2,y2);
for i:=1 to n do
for j:=1 to m do begin
read(f,a[i,j]);
if a[i,j]=0 then b[i,j]:=1
end;
{BORDEZ MATRICEA B CU 1}
for i:=0 to n+1 do begin
b[i,0]:=1;
b[i,m+1]:=1
end;
for i:=0 to m+1 do begin
b[0,i]:=1;
b[n+1,i]:=1
end;
{INITIALIZEZ O COADA CU PUNCTUL DE PORNIRE}
b[x1,y1]:=2;
cx[1]:=x1;
cy[1]:=y1;
ls:=1;
ld:=1;
gasit:=false;
{ADAUG IN COADA VECINII PUNCTULUI CURENT
CAT TIMP N-AM AJUNS LA DESTINATIE}
while not gasit do
begin
if b[cx[ls],cy[ls]+1]=0 then begin
ld:=ld+1;
cx[ld]:=cx[ls];
cy[ld]:=cy[ls]+1;
b[cx[ls],cy[ls]+1]:=b[cx[ls],cy[ls]]+1;
end;
if b[cx[ls],cy[ls]-1]=0 then begin
ld:=ld+1;
cx[ld]:=cx[ls];
cy[ld]:=cy[ls]-1;
b[cx[ls],cy[ls]-1]:=b[cx[ls],cy[ls]]+1;
end;
if b[cx[ls]+1,cy[ls]]=0 then begin
ld:=ld+1;
cx[ld]:=cx[ls]+1;
cy[ld]:=cy[ls];
b[cx[ls]+1,cy[ls]]:=b[cx[ls],cy[ls]]+1;
end;
if b[cx[ls]-1,cy[ls]]=0 then begin
ld:=ld+1;
cx[ld]:=cx[ls]-1;
cy[ld]:=cy[ls];
b[cx[ls]-1,cy[ls]]:=b[cx[ls],cy[ls]]+1;
end;
ls:=ls+1;
if b[x2,y2]<>0 then gasit:=true
end;
{PARCURG DRUMUL INAPOI
lung:=1;
x:=x2;
y:=y2;
gasit:=false;
while not gasit do
begin
if (b[x,y]>b[x+1,y])and(b[x+1,y]<>0)
then x:=x+1
else if (b[x,y]>b[x-1,y])and(b[x-1,y]<>0)
then x:=x-1
else if (b[x,y]>b[x,y+1])and(b[x,y+1]<>0)
then y:=y+1
else if (b[x,y]>b[x,y-1])and(b[x,y-1]<>0) then y:=y-1;
lung:=lung+1;
if (x=x1)and(y=y1)then gasit:=true
end; }
close(f);
assign(f,'kdrum.out');
rewrite(f);
writeln(f,b[x2,y2]-1);
close(f);
end.