#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1500 + 10;
const long long INF = (1LL << 60);
long long sum[MAXN];
int n, m;
long long a;
long long dp[MAXN][2];
long long ans = -INF;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (__typeof(n) i = (0); i < (n); ++i) {
    for (__typeof(m) j = (0); j < (m); ++j) {
      cin >> a;
      sum[j] = ((j > 0) ? sum[j - 1] : 0) + a;
    }
    if (i % 2 == 0) {
      dp[0][0] = -INF;
      for (__typeof(m) j = (1); j < (m); ++j) {
        dp[j][0] = sum[j] + max(dp[j - 1][0] - sum[j - 1], dp[j - 1][1]);
      }
    } else {
      dp[m - 1][1] = -INF;
      for (__typeof(m - 2) j = (m - 2); j >= (0); --j) {
        dp[j][1] = sum[j] + max(dp[j + 1][1] - sum[j + 1], dp[j + 1][0]);
      }
    }
  }
  for (__typeof(m) j = (0); j < (m); ++j) {
    ans = max(ans, dp[j][(n - 1) % 2]);
  }
  cout << ans << endl;
  return 0;
}
