#include <bits/stdc++.h>
using namespace std;
const int maxn = 1510;
const int oo = 1e17;
int m, n;
int a[maxn][maxn];
long long f[maxn][maxn];
int main() {
  scanf("%d%d", &m, &n);
  for (int i = (1), _b = (m); i <= _b; ++i)
    for (int j = (1), _b = (n); j <= _b; ++j) scanf("%d", &a[i][j]);
  for (int i = (1), _b = (m); i <= _b; ++i) {
    long long first = -oo;
    long long s = 0;
    if (i % 2) {
      for (int j = (1), _b = (n); j <= _b; ++j) {
        if (j > 1) first = max(first, f[i - 1][j - 1]);
        s += a[i][j];
        f[i][j] = s + first;
      }
    } else {
      for (int j = (1), _b = (n); j <= _b; ++j) s += a[i][j];
      for (int j = (n), _b = (1); j >= _b; --j) {
        if (j < n) first = max(first, f[i - 1][j + 1]);
        s -= a[i][j + 1];
        f[i][j] = s + first;
      }
    }
  }
  long long ans = -oo;
  for (int i = (1), _b = (n); i <= _b; ++i) ans = max(ans, f[m][i]);
  printf("%I64d", ans);
  return 0;
}
