n, m = map(int, input().split())
dp = list(map(int, input().split()))
pa = dp[:]
if n == 1:
    print(0)
    exit()
for _ in range(n - 1):
    a = list(map(int, input().split()))
    mn = min(dp)
    dp = [min(dp[j] + a[j], mn + pa[j] + a[j]) for j in range(m)]
    pa = a
print(min(dp))