#include <bits/stdc++.h>
using namespace std;
long long a[2002], b[2002];
long long s[2002][2002];
const long long inf = 100000000000ll;
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  int tmp;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &tmp);
      s[i][j] = s[i][j - 1] + (long long)tmp;
    }
  }
  long long ans = -inf;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) b[j] = a[j];
    if (i % 2 == 1) {
      a[1] = -inf;
      long long mx = b[1];
      for (int j = 2; j <= m; j++) {
        a[j] = mx + s[i][j];
        mx = max(mx, b[j]);
      }
    } else {
      a[m] = -inf;
      long long mx = b[m];
      for (int j = m - 1; j > 0; j--) {
        a[j] = mx + s[i][j];
        mx = max(mx, b[j]);
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    ans = max(ans, a[i]);
  }
  cout << ans;
  return 0;
}
