#include <bits/stdc++.h>
using namespace std;
const int mx = 1505;
using ll = long long;
const ll INF = 1LL << 60;
ll pref[mx][mx], dp[mx], f[mx];
template <typename T>
void fastscan(T& x) {
  x = 0;
  register T c;
  do {
    c = getchar();
  } while (c == ' ' || c == '\n');
  bool neg = 0;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  while (c != EOF && c <= 57 && c >= 48) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (neg) x *= -1;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int x;
      fastscan(x);
      pref[i][j] = pref[i][j - 1] + x;
    }
  }
  ll a;
  for (int i = 1; i <= n; i++) {
    if (i & 1) {
      a = f[1];
      dp[1] = -INF;
      for (int j = 2; j <= m; j++) {
        dp[j] = pref[i][j] + a;
        a = max(a, f[j]);
      }
    } else {
      a = f[m];
      dp[0] = dp[m] = -INF;
      for (int j = m - 1; j > 0; j--) {
        dp[j] = pref[i][j] + a;
        a = max(a, f[j]);
      }
    }
    memcpy(f, dp, sizeof(f));
  }
  ll ans = -INF;
  for (int j = 1; j <= m; j++) ans = max(ans, dp[j]);
  cout << ans;
}
