#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000;
long long inf = (1000 * 1000 * 1000);
int a[MAXN][MAXN];
long long s[MAXN][MAXN];
long long d[MAXN][MAXN], n, m;
int main() {
  inf *= 1000;
  inf *= 1000;
  int N, M;
  scanf("%d%d", &N, &M);
  n = N;
  m = M;
  for (int i = 0; i < n; ++i) {
    long long summ = 0;
    for (int j = 0; j < m; ++j) {
      int curr;
      scanf("%d", &curr);
      a[i][j] = curr;
      summ += a[i][j];
      s[i][j] = summ;
    }
  }
  long long cMax;
  d[0][m] = -inf;
  cMax = s[0][m - 1];
  for (int j = m - 1; j >= 0; --j) {
    d[0][j] = cMax;
    cMax = max((long long)cMax, s[0][j - 1]);
  }
  for (int i = 1; i < n - 1; ++i) {
    if (i % 2 == 0) {
      long long Max;
      d[i][m] = -inf;
      Max = d[i - 1][m] + s[i][m - 1];
      for (int j = m - 1; j >= 0; --j) {
        d[i][j] = Max;
        if (j > 0) Max = max(Max, s[i][j - 1] + d[i - 1][j]);
      }
    } else {
      long long Max;
      d[i][1] = -inf;
      d[i][0] = -inf;
      Max = d[i - 1][1] + s[i][0];
      for (int j = 2; j <= m; ++j) {
        d[i][j] = Max;
        Max = max(Max, s[i][j - 1] + d[i - 1][j]);
      }
    }
  }
  if (n % 2 == 0) {
    d[n - 1][0] = -inf;
    for (int j = 1; j <= m; ++j) {
      d[n - 1][j] = d[n - 2][j] + s[n - 1][j - 1];
    }
  } else {
    d[n - 1][0] = -inf;
    for (int j = m; j > 0; --j) {
      d[n - 1][j] = d[n - 2][j] + s[n - 1][j - 1];
    }
  }
  long long Max = -inf;
  for (int j = 0; j < m + 1; ++j) Max = max(Max, d[n - 1][j]);
  cout << Max;
  return 0;
}
