#include <bits/stdc++.h>
using namespace std;
void RunProgram();
int main() {
  int nTests = 1;
  while (nTests--) RunProgram(), printf("\n");
}
const int MAX = 1505;
const long long INF = (long long)1e15;
int a[MAX][MAX], R, C;
long long f[MAX], maxL[MAX], maxR[MAX];
void RunProgram() {
  scanf("%d%d", &R, &C);
  for (int i = 1; i <= R; i++)
    for (int j = 1; j <= C; j++) scanf("%d", &a[i][j]);
  memset(f, 0, sizeof(f));
  memset(maxL, 0, sizeof(f));
  memset(maxR, 0, sizeof(f));
  for (int i = 1; i <= R; i++) {
    int sum = 0;
    if (i & 1) {
      f[1] = -INF, sum = a[i][1];
      for (int j = 2; j <= C; j++) {
        sum += a[i][j];
        f[j] = sum + maxL[j - 1];
      }
    } else {
      for (int j = 1; j < C; j++) {
        sum += a[i][j];
        f[j] = sum + maxR[j + 1];
      }
      f[C] = -INF;
    }
    maxL[1] = f[1];
    for (int j = 2; j <= C; j++) maxL[j] = max(f[j], maxL[j - 1]);
    maxR[C] = f[C];
    for (int j = C - 1; j >= 1; j--) maxR[j] = max(f[j], maxR[j + 1]);
  }
  long long res = (long long)*max_element(f + 1, f + C + 1);
  cout << res;
}
