program number;
type
shuzu=array[1..10,1..10] of longint;
shuzu1=array[1..2] of integer;
var
s:shuzu;
xx,yy:shuzu1;
i,j,m,n,min:longint;
procedure print(c:longint);
begin
if (c<min)and(c>0) then min:=c;
end;
procedure search(x,y,c:longint);
var
k,v:longint;
begin
for k:=1 to 2 do
begin
if (x+xx[k]<=m)and(y+yy[k]<=n) then
begin
x:=x+xx[k]; y:=y+yy[k];
c:=c+s[x,y];
if (x=m)and(y=n) then print(c)
else search(x,y,c);
end;
end;
end;
begin
assign(input,'number.in');reset(input);
assign(output,'number.out');rewrite(output);
readln(m,n);
xx[1]:=1; xx[2]:=0; yy[1]:=0; yy[2]:=1;
for i:=1 to m do
begin
for j:=1 to n do
read(s[i,j]);
readln;
end;
min:=maxlongint;
search(1,1,0);
if min=maxlongint then writeln('-1')
else writeln(min);
close(output);
end.