program number;
var
m,n,t,ans:integer;
data:array[0..11,0..11]of integer;
procedure init;
var
i,j:integer;
begin
assign(input,'number.in');
reset(input);
assign(output,'number.out');
rewrite(output);
readln(m,n);
for i:=1 to m do
begin
for j:=1 to n do read(data[i,j]);
readln;
end;
close(input);
ans:=maxint; t:=data[1,1];
end;
procedure try(x,y:integer);
begin
if (x>=1)and(x<=m)and(y>=1)and(y<=n) then
if (x=m)and(y=n) then
begin
if (t<ans)and(t>0) then ans:=t;
end
else
begin
t:=t+data[x,y+1];
try(x,y+1);
t:=t-data[x,y+1];
t:=t+data[x+1,y];
try(x+1,y);
t:=t-data[x+1,y];
end;
end;
begin
init;
try(1,1);
if ans=maxint then writeln(-1)
else writeln(ans);
close(output);
end.