#include <bits/stdc++.h>
using namespace std;
long long a[1509][1509], maxp[1509][1509], maxs[1509][1509], s[1509][1509],
    dp[1509][1509];
long long i, j, k, l, n, m, res = -10000000000;
int main() {
  scanf("%I64d %I64d", &n, &m);
  for (i = 1; i <= n; i++) {
    maxp[i][0] = -10000000000;
    maxs[i][m + 1] = -10000000000;
    for (j = 1; j <= m; j++) {
      scanf("%I64d", &a[i][j]);
      s[i][j] = s[i][j - 1] + a[i][j];
      if (i % 2 == 0) {
        dp[i][j] = s[i][j] + maxs[i - 1][j + 1];
      } else
        dp[i][j] = s[i][j] + maxp[i - 1][j - 1];
      if (i % 2 == 0) maxp[i][j] = max(maxp[i][j - 1], dp[i][j]);
      if (i == n) res = max(res, dp[i][j]);
    }
    if (i % 2 == 1) {
      for (j = m; j > 0; j--) maxs[i][j] = max(maxs[i][j + 1], dp[i][j]);
    }
  }
  printf("%I64d\n", res);
  return 0;
}
