#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000;
const long long inf = (1ll) << 44;
long long a[maxn][maxn], sum[maxn][maxn], f[maxn][maxn], maxv[maxn][maxn];
int n, m;
template <class T>
void scan(T& a) {
  a = 0;
  bool flag = false;
  char ch = getchar();
  if (ch == '-')
    flag = true;
  else if (ch >= '0' && ch <= '9')
    a = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9') a = a * 10 + ch - '0';
  if (flag) a = -a;
}
int main() {
  scan(n);
  scan(m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scan(a[i][j]);
      sum[i][j] = sum[i][j - 1] + a[i][j];
    }
  maxv[1][m + 1] = -inf;
  for (int i = m; i >= 1; i--) {
    f[1][i] = sum[1][i];
    maxv[1][i] = max(maxv[1][i + 1], f[1][i]);
  }
  for (int i = 2; i <= n; i++) {
    if (i & 1) {
      for (int j = 1; j <= m; j++) f[i][j] = sum[i][j] + maxv[i - 1][j - 1];
      maxv[i][m + 1] = -inf;
      for (int j = m; j >= 1; j--) maxv[i][j] = max(maxv[i][j + 1], f[i][j]);
    } else {
      for (int j = m; j >= 1; j--) f[i][j] = sum[i][j] + maxv[i - 1][j + 1];
      maxv[i][0] = -inf;
      for (int j = 1; j <= m; j++) maxv[i][j] = max(maxv[i][j - 1], f[i][j]);
    }
  }
  printf("%lld\n", max(maxv[n][1], maxv[n][m]));
}
