#include <bits/stdc++.h>
using namespace std;
int n, m;
long long sum[1505][1505];
long long ans[1505];
long long t[1505];
int main() {
  int i, j, x;
  long long val, now, res;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      scanf("%I64d", &val), sum[i][j] = sum[i][j - 1] + val;
  for (i = 1; i <= m; i++) ans[i] = sum[1][i];
  for (i = 2; i <= n; i++) {
    if (i % 2 == 0) {
      now = -(long long)1e15;
      for (x = m; x > 0; x--) {
        t[x] = now + sum[i][x];
        now = max(now, ans[x]);
      }
    } else {
      now = -(long long)1e15;
      for (x = 1; x <= m; x++) {
        t[x] = now + sum[i][x];
        now = max(now, ans[x]);
      }
    }
    for (x = 1; x <= m; x++) ans[x] = t[x];
  }
  res = -(long long)1e15;
  for (x = 1; x <= m; x++) res = max(res, ans[x]);
  printf("%I64d", res);
}
