#include <bits/stdc++.h>
using namespace std;
const long long INF = 1 << 30;
int N, M;
long long L[1500][1500];
int main() {
  cin >> N >> M;
  int v;
  for (int i = 0; i < N; ++i) {
    long long sum = 0;
    for (int j = 0; j < M; ++j) {
      scanf("%d", &v);
      sum += v;
      L[i][j] = sum;
    }
  }
  vector<long long> cur(L[0], L[M]);
  vector<long long> next(M);
  for (int i = 1; i < N; ++i) {
    if (i % 2 == 0) {
      next[0] = -INF;
      long long opt = -INF;
      for (int j = 1; j < M; ++j) {
        opt = max(opt, cur[j - 1]);
        next[j] = L[i][j] + opt;
      }
    } else {
      next[M - 1] = -INF;
      long long opt = -INF;
      for (int j = M - 2; j >= 0; --j) {
        opt = max(opt, cur[j + 1]);
        next[j] = L[i][j] + opt;
      }
    }
    swap(cur, next);
  }
  long long ans = -INF;
  for (int i = 0; i < M; ++i) {
    ans = max(ans, cur[i]);
  }
  cout << ans << endl;
  return 0;
}
