program kdrum;
var f,g:text;
x,a:array[0..52,0..52] of longint;
ln,ln2,col,col2:array[1..2501] of integer;
nr2,x1,x2,y1,y2,nr,n,m,k,i,j:longint;
begin
assign(f,'kdrum.in');
assign(g,'kdrum.out');
reset(f);
rewrite(g);
read(f,n,m,k);readln(f);
read(f,x1,y1,x2,y2);
for i:=1 to n do
begin
readln(f);
for j:=1 to m do
begin
read(f,a[i,j]);
x[i,j]:=maxlongint;
end;
end;
nr:=0;a[x1,y1]:=0;
if a[x1-1,y1]<>0 then begin nr:=nr+1; ln[nr]:=x1-1;col[nr]:=y1; x[x1-1,y1]:=1;end;
if a[x1,y1+1]<>0 then begin nr:=nr+1; ln[nr]:=x1;col[nr]:=y1+1; x[x1,y1+1]:=1;end;
if a[x1+1,y1]<>0 then begin nr:=nr+1; ln[nr]:=x1+1;col[nr]:=y1; x[x1+1,y1]:=1;end;
if a[x1,y1-1]<>0 then begin nr:=nr+1; ln[nr]:=x1;col[nr]:=y1-1; x[x1,y1-1]:=1;end;
while nr<>0 do
begin
nr2:=0;
for i:=1 to nr do
begin
if (a[ln[i]-1,col[i]]<>0) and (x[ln[i]-1,col[i]]>x[ln[i],col[i]]) then begin nr2:=nr2+1; ln2[nr2]:=ln[i]-1;col2[nr2]:=col[i];
x[ln[i]-1,col[i]]:=x[ln[i],col[i]]+1;end;
if (a[ln[i],col[i]+1]<>0) and (x[ln[i],col[i]+1]>x[ln[i],col[i]]) then begin nr2:=nr2+1; ln2[nr2]:=ln[i];col2[nr2]:=col[i]+1;
x[ln[i],col[i]+1]:=x[ln[i],col[i]]+1;end;
if (a[ln[i]+1,col[i]]<>0) and (x[ln[i]+1,col[i]]>x[ln[i],col[i]]) then begin nr2:=nr2+1; ln2[nr2]:=ln[i]+1;col2[nr2]:=col[i];
x[ln[i]+1,col[i]]:=x[ln[i],col[i]]+1;end;
if (a[ln[i],col[i]-1]<>0) and (x[ln[i],col[i]-1]>x[ln[i],col[i]]) then begin nr2:=nr2+1; ln2[nr2]:=ln[i];col2[nr2]:=col[i]-1;
x[ln[i],col[i]-1]:=x[ln[i],col[i]]+1;end;
end;
nr:=nr2;
ln:=ln2;col:=col2;
end;
write(g,x[x2,y2]+1);
closE(f);
close(g);
end.