#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000")
using namespace std;
template <typename T>
inline T abs(T a) {
  return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
  return a * a;
}
const long long INF = (long long)1E18 + 7;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
const int NMAX = 2000;
int n, m;
int a[NMAX][NMAX];
long long sum[NMAX][NMAX];
long long d[NMAX][NMAX];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < int(n); ++i)
    for (int j = 0; j < int(m); ++j) {
      scanf("%d", &a[i][j]);
      sum[i][j] = (j == 0 ? 0 : sum[i][j - 1]) + a[i][j];
    }
  for (int i = 0; i < int(n); ++i)
    for (int j = 0; j < int(m); ++j) d[i][j] = -INF;
  for (int j = 0; j < int(m); ++j) d[0][j] = sum[0][j];
  for (int i = 0; i < int(n - 1); ++i) {
    if (i & 1) {
      long long maxV = -INF;
      for (int j = 0; j < int(m); ++j) {
        if (maxV != -INF) d[i + 1][j] = max(d[i + 1][j], maxV + sum[i + 1][j]);
        maxV = max(maxV, d[i][j]);
      }
    } else {
      long long maxV = -INF;
      for (int j = int(m) - 1; j >= 0; --j) {
        if (maxV != -INF) d[i + 1][j] = max(d[i + 1][j], maxV + sum[i + 1][j]);
        maxV = max(d[i][j], maxV);
      }
    }
  }
  long long ans = -INF;
  for (int j = 0; j < int(m); ++j) ans = max(ans, d[n - 1][j]);
  cout << ans << endl;
  return 0;
}
