program pascal;
var f,g:text; a,b:array[1..50,1..50] of integer; u,v:array[1..2500]of integer;
i,j,k,n,m,x1,x2,y1,y2,pi,ps:longint;
procedure citire;
begin
assign(f,'kdrum.in'); reset(f);
assign(g,'kdrum.out'); rewrite(g);
readln(f,n,m,k); readln(f,x1,y1,x2,y2);
for i:=1 to n do
for j:=1 to m do read(f,a[i,j]);
end;
procedure lee;
begin
ps:=1; pi:=1; v[ps]:=x1; u[ps]:=y1; b[v[ps],u[ps]]:=1; a[v[ps],u[ps]]:=0;
while pi<=ps do
begin
if v[pi]-1>0 then
if a[v[pi]-1,u[pi]]<>0 then
begin
inc(ps); v[ps]:=v[pi]-1; u[ps]:=u[pi]; a[v[ps],u[ps]]:=0;
b[v[ps],u[ps]]:=b[v[pi],u[pi]]+1;
end;
if v[pi]+1<n+1 then
if a[v[pi]+1,u[pi]]<>0 then
begin
inc(ps); v[ps]:=v[pi]+1; u[ps]:=u[pi]; a[v[ps],u[ps]]:=0;
b[v[ps],u[ps]]:=b[v[pi],u[pi]]+1;
end;
if u[pi]-1>0 then
if a[v[pi],u[pi]-1]<>0 then
begin
inc(ps); v[ps]:=v[pi]; u[ps]:=u[pi]-1; a[v[ps],u[ps]]:=0;
b[v[ps],u[ps]]:=b[v[pi],u[pi]]+1;
end;
if u[pi]+1<m+1 then
if a[v[pi],u[pi]+1]<>0 then
begin
inc(ps); v[ps]:=v[pi]; u[ps]:=u[pi]+1; a[v[ps],u[ps]]:=0;
b[v[ps],u[ps]]:=b[v[pi],u[pi]]+1;
end;
pi:=pi+1;
end;
end;
procedure afisare;
begin
write(g,b[x2,y2]);
close(f);
close(g);
end;
begin
citire;
lee;
afisare;
end.