ll@n,@m,@a[m],b[m],d[m],x=0; d[0..m-1]=ll_inf; rep(f,1,n){ rd(b(m)); rep(j,m){ d[j]=min(d[j],x+a[j])+b[j]; a[j]=b[j]; } x=min(d(m)); } wt(x);