from itertools import product h,w = map(int,input().split()) a = [[0]*(w+3)]+[[0]+list(map(int,input().split()))+[0,0] for _ in range(h)]+[[0]*(w+3),[0]*(w+3)] s = []; ans = 0 for x in range(h+2): for dx in range(-1,2): px = x+dx; py = 1; t = set() while a[px][py]: t.add((px,py)); px += dx; py += 1 s.append(t) for y in range(w+2): for dy in range(-1,2): px = 1; py = y+dy; t = set() while a[px][py]: t.add((px,py)); px += 1; py += dy s.append(t) for si in s: for sj in s: ans = max(ans,sum(a[x][y] for x,y in si|sj)) print(ans)