#include <bits/stdc++.h>
using namespace std;
int n, m, a[2000][2000];
long long dp[2000][2000], v[2000][2000];
long long INF = 1LL << 60;
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);
  for (int i = 0; i < (int)(n); i++) {
    v[i][0] = 0;
    for (int j = 0; j < (int)(m); j++) v[i][j + 1] = v[i][j] + a[i][j];
  }
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(m + 1); j++) dp[i][j] = -INF;
  for (int i = 0; i < (int)(m + 1); i++) dp[0][i] = v[0][i];
  for (int i = 0; i < (int)(n - 1); i++) {
    if (i % 2) {
      int jj = 0;
      long long mx = -INF;
      for (int j = 1; j < m + 1; j++) {
        while (jj < j) {
          mx = max(mx, dp[i][jj]);
          jj++;
        }
        if (mx != -INF) dp[i + 1][j] = mx + v[i + 1][j];
      }
    } else {
      int jj = m;
      long long mx = -INF;
      for (int j = m; j > 0; j--) {
        while (jj > j) {
          mx = max(mx, dp[i][jj]);
          jj--;
        }
        if (mx != -INF) dp[i + 1][j] = mx + v[i + 1][j];
      }
    }
  }
  long long ans = -INF;
  for (int i = 0; i < (int)(m + 1); i++) ans = max(ans, dp[n - 1][i]);
  cout << ans << endl;
  return 0;
}
