import sys
from collections import deque

input = sys.stdin.readline

n, m = map(int, input().split())
maze = []
for i in range(n):
    maze.append(list(map(int, input().split())))

    for j in range(m):
        a = 0 if i == 0 else maze[i - 1][j]
        b = 0 if j == 0 else maze[i][j - 1]
        c = 0 if i == 0 or j == 0 else maze[i - 1][j - 1]

        maze[i][j] = maze[i][j] + max(a, b, c)

print(maze[n - 1][m - 1])
