#include <bits/stdc++.h>
using namespace std;
const int MAX = 1515;
const long long INF = (long long)1e13;
int n, m;
int a[MAX][MAX];
long long f[MAX][MAX], mx[MAX][MAX];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    a[i][0] = 0;
    for (int j = 1; j <= m; ++j) {
      scanf("%d", &a[i][j]);
      a[i][j] += a[i][j - 1];
    }
  }
  for (int j = 0; j <= m; ++j) f[0][j] = mx[0][j] = 0;
  for (int i = 1; i <= n; ++i) {
    f[i][0] = -INF;
    for (int j = 1; j <= m; ++j) {
      f[i][j] = f[i][j - 1];
      if (i % 2 == 0)
        f[i][j] = max(f[i][j], mx[i - 1][j + 1] + a[i][j]);
      else
        f[i][j] = max(f[i][j], f[i - 1][j - 1] + a[i][j]);
    }
    if (i % 2 == 0) f[i][m] = f[i][m - 1];
    if (i % 2 == 0)
      mx[i][m] = -INF;
    else
      mx[i][m] = f[i - 1][m - 1] + a[i][m];
    for (int j = m - 1; j > 0; --j) {
      mx[i][j] = mx[i][j + 1];
      if (i % 2 == 0)
        mx[i][j] = max(mx[i][j], mx[i - 1][j + 1] + a[i][j]);
      else
        mx[i][j] = max(mx[i][j], f[i - 1][j - 1] + a[i][j]);
    }
    mx[i][0] = mx[i][1];
  }
  cout << f[n][m];
  return 0;
}
