#include <iostream>
#include <vector>
using namespace std;

int main() {
    int h, w;
    cin >> h >> w;

    vector<vector<int>> dp(h+1, vector<int>(w+1));
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            int val;
            cin >> val;
            dp[i][j] = val + max(dp[i-1][j], dp[i][j-1]);
        }
    }

    cout << dp[h][w] << endl;

    return 0;
}
