#include <bits/stdc++.h>
using namespace std;
long long int a[1511][1511];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    a[i][0] = 0;
    for (int j = 0; j < m; j++) {
      int t;
      scanf("%d", &t);
      a[i][j + 1] = a[i][j] + t;
    }
  }
  long long int res[2][1511];
  memcpy(res, a[0], sizeof a[0]);
  res[0][1] = res[1][m] = -10000000000000;
  for (int i = 1; i < n; i++) {
    if (i % 2 == 0) {
      long long int mres = res[1][1];
      for (int j = 2; j <= m; j++) {
        res[0][j] = mres + a[i][j];
        mres = max(mres, res[1][j]);
      }
    } else {
      long long int mres = res[0][m];
      for (int j = m - 1; j > 0; j--) {
        res[1][j] = mres + a[i][j];
        mres = max(mres, res[0][j]);
      }
    }
  }
  long long int r = res[1 - n % 2][1];
  for (int i = 1; i <= m; i++) {
    r = max(r, res[1 - n % 2][i]);
  }
  cout << r;
}
