import itertools as iter import collections as coll import heapq as hq import bisect as bis from decimal import Decimal as dec from functools import cmp_to_key import math import sys #import pypyjit #pypyjit.set_param('max_unroll_recursion=-1') sys.setrecursionlimit(10 ** 6) inp = sys.stdin.readline input = lambda : inp().rstrip() getN = lambda : int(inp()) getNs = lambda : map(int, inp().split()) getList = lambda :list(map(int, inp().split())) getStrs = lambda n : [input() for _ in [0] * n] def yexit(): print("Yes"); exit(0) def nexit(): print("No"); exit(0) pi = 3.141592653589793 mod = 1000000007 MOD = 998244353 INF = 4611686018427387903 dx = [1, 0, -1, 0]; dy = [0, 1, 0, -1] #di = coll.defaultdict(int) """ Main Code """ n, m = getNs() a = [getList() for _ in [0]*n] dp = [[[INF]*2 for _ in [0]*m] for _ in [0]*n] dp[0][0][0] = 0 que = [(0,0,0,0)] while(que): #print(que) c,p,q,r = hq.heappop(que) if(c > dp[p][q][r]): continue if(p == n - 1): print(c) break if(q > 0 and c < dp[p][q-1][0]): dp[p][q-1][0] = c hq.heappush(que, (c,p,q-1,0)) if(q < m - 1 and c < dp[p][q+1][0]): dp[p][q+1][0] = c hq.heappush(que, (c,p,q+1,0)) if(r == 0): nc = c + a[p][q] if(nc >= dp[p][q][1]): continue dp[p][q][1] = nc hq.heappush(que, (nc,p,q,1)) else: nc = c + a[p+1][q] if(nc >= dp[p+1][q][1]): continue dp[p+1][q][1] = nc hq.heappush(que, (nc,p+1,q,1))