#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int n, m;
int a[2005], s[2005];
long long dp[2005], pre[2005];
int main() {
  scanf("%d %d", &n, &m);
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; ++i) {
    memcpy(pre, dp, sizeof(dp));
    s[0] = 0;
    for (int j = 1; j <= m; ++j) {
      scanf("%d", &a[j]);
      s[j] = s[j - 1] + a[j];
    }
    if (i % 2 == 1) {
      long long mx = pre[1];
      for (int j = 2; j <= m; ++j) {
        dp[j] = mx + s[j];
        mx = max(mx, pre[j]);
      }
    } else {
      long long mx = pre[m];
      for (int j = m - 1; j >= 1; --j) {
        dp[j] = mx + s[j];
        mx = max(mx, pre[j]);
      }
    }
  }
  long long ans = -INF;
  if (n % 2 == 1) {
    for (int j = 2; j <= m; ++j) ans = max(ans, dp[j]);
  } else {
    for (int j = 1; j < m; ++j) ans = max(ans, dp[j]);
  }
  cout << ans << endl;
  return 0;
}
