1N, M = map(int, input().split())
2dp = [list(map(int, input().split())) for _ in range(N)]
3
4for i in range(1, N):
5 dp[i][0] = dp[i][0]+dp[i-1][0]
6for i in range(1, M):
7 dp[0][i] = dp[0][i]+dp[0][i-1]
8
9for i in range(1, N):
10 for j in range(1, M):
11 dp[i][j] = dp[i][j]+max(dp[i-1][j], dp[i][j-1])
12
13print (dp[N-1][M-1])