from collections import defaultdict h, w = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(h)] T = defaultdict(int) Y = defaultdict(int) P = defaultdict(int) M = defaultdict(int) for i in range(h): for j in range(w): T[i] += A[i][j] Y[j] += A[i][j] P[i + j] += A[i][j] M[i - j] += A[i][j] ans = 0 L = [T, Y, P, M] for C in L: for i in C: for j in C: if i == j: continue ans = max(ans, C[i] + C[j]) for i in T: for j in Y: ans = max(ans, T[i] + Y[j] - A[i][j]) for i in T: for j in P: x = i y = j - i if 0 <= y < w: ans = max(ans, T[i] + P[j] - A[x][y]) else: ans = max(ans, T[i] + P[j]) for i in T: for j in M: x = i y = i - j if 0 <= y < w: ans = max(ans, T[i] + M[j] - A[x][y]) else: ans = max(ans, T[i] + M[j]) for i in Y: for j in P: x = j - i y = i if 0 <= x < h: ans = max(ans, Y[i] + P[j] - A[x][y]) else: ans = max(ans, Y[i] + P[j]) for i in Y: for j in M: x = i + j y = i if 0 <= x < h: ans = max(ans, Y[i] + M[j] - A[x][y]) else: ans = max(ans, Y[i] + M[j]) for i in P: for j in M: x = (i + j) / 2 y = (i - j) / 2 if int(x) == x and int(y) == y and 0 <= x < h and 0 <= y < w: x = int(x) y = int(y) ans = max(ans, P[i] + M[j] - A[x][y]) else: ans = max(ans, P[i] + M[j]) print(ans)