#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long dp[1501][1501];
long long a[1510][1501];
long long func(long long here, long long here1) {
  if (here1 > m) return -999999999999999;
  if (here1 < 1) return -999999999999999;
  if (here == n + 1) return 0;
  long long &ret = dp[here][here1];
  if (ret != -1) return ret;
  ret = -999999999999999;
  if (here % 2) {
    ret = max(ret, func(here, here1 + 1));
    ret = max(ret, func(here + 1, here1 - 1) + a[here][here1]);
  } else {
    ret = max(ret, func(here, here1 - 1));
    ret = max(ret, func(here + 1, here1 + 1) + a[here][here1]);
  }
  return ret;
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%lld %lld", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int y = 1; y <= m; y++) {
      scanf("%lld", &a[i][y]);
      a[i][y] += a[i][y - 1];
    }
  }
  printf("%lld\n", func(1, 1));
}
