#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  int a[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> a[i][j];
  }
  long long dp[n][m], temp = 0;
  for (int i = 0; i < m; i++) {
    temp += a[0][i];
    dp[0][i] = temp;
  }
  for (int i = 1; i < n; i++) {
    if (i % 2 == 1) {
      temp = 0;
      for (int j = 0; j < m - 1; j++) temp += a[i][j];
      long long max = dp[i - 1][m - 1];
      dp[i][m - 1] = -1e18;
      for (int j = m - 1; j >= 1; j--) {
        max = std::max(max, dp[i - 1][j]);
        dp[i][j - 1] = max + temp;
        temp -= a[i][j - 1];
      }
    } else {
      temp = a[i][0];
      long long max = dp[i - 1][0];
      dp[i][0] = -1e18;
      for (int j = 1; j < m; j++) {
        temp += a[i][j];
        max = std::max(max, dp[i - 1][j - 1]);
        dp[i][j] = max + temp;
      }
    }
  }
  long long ans = -1e18;
  for (int i = 0; i < m; i++) ans = max(ans, dp[n - 1][i]);
  cout << ans << endl;
}
