#include <bits/stdc++.h>
using namespace std;
int n, m;
long long a[1555][1555], f[1555][1555];
int main() {
  scanf("%d%d", &n, &m);
  for (int(i) = 0; (i) < (n); ++(i)) {
    scanf("%lld", &a[i][1]);
    for (int j = 2; j <= m; ++j) {
      scanf("%lld", &a[i][j]);
      a[i][j] += a[i][j - 1];
    }
  }
  for (int(i) = 0; (i) < (n); ++(i))
    for (int j = 1; j <= m; ++j) f[i][j] = -1000000000000000LL;
  for (int j = 1; j <= m; ++j) f[0][j] = a[0][j];
  for (int(i) = 0; (i) < (n - 1); ++(i)) {
    if (i % 2 == 0) {
      long long v = f[i][m];
      for (int j = m - 1; j > 0; --j) {
        f[i + 1][j] = max(f[i + 1][j], v + a[i + 1][j]);
        v = max(v, f[i][j]);
      }
    } else {
      long long v = f[i][1];
      for (int j = 2; j <= m; ++j) {
        f[i + 1][j] = max(f[i + 1][j], v + a[i + 1][j]);
        v = max(v, f[i][j]);
      }
    }
  }
  long long ans = -1000000000000000LL;
  for (int j = 1; j <= m; ++j) ans = max(ans, f[n - 1][j]);
  cout << ans << endl;
}
