#include <bits/stdc++.h>
using namespace std;
const int N = 1520;
long long int a[N][N];
long long int s[N][N] = {0};
long long int maxi[N][N] = {0};
long long int INF = 1e17;
int main() {
  int m, n;
  cin >> m >> n;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) scanf("%I64d", &a[i][j]);
    for (int j = 1; j <= n; j++) {
      s[i][j] = a[i][j] + s[i][j - 1];
    }
  }
  for (int i = m; i > 0; i--) {
    if (i % 2 == 0) {
      for (int j = 1; j < n; j++) {
        a[i][j] = s[i][j] + maxi[i + 1][j + 1];
      }
      maxi[i][1] = a[i][1];
      for (int j = 2; j < n; j++) {
        maxi[i][j] = max(maxi[i][j - 1], a[i][j]);
      }
    } else {
      for (int j = 2; j <= n; j++) a[i][j] = s[i][j] + maxi[i + 1][j - 1];
      maxi[i][n] = a[i][n];
      for (int j = n - 1; j > 1; j--) maxi[i][j] = max(maxi[i][j + 1], a[i][j]);
    }
  }
  long long int res = maxi[1][2];
  cout << res << endl;
}
