N,M = map(int,input().split()) A = [list(map(int,input().split())) for _ in range(N)] import sys if N == 1: print(0) exit() inf = 10 ** 15 dp = [[inf] * M for _ in range(N)] for i in range(M): dp[0][i] = A[0][i] for i in range(1,N): s = min(dp[i-1]) for j in range(M): dp[i][j] = min(dp[i-1][j] + A[i][j],s + A[i][j] + A[i-1][j]) ans = inf for j in range(M): if dp[-1][j] < ans: ans = dp[-1][j] print(ans)