#include <bits/stdc++.h>
using namespace std;
long long int sm[2002][2002], a[2002][2002], dp[2002][2002];
int cnt[2002][2002];
long long int INF = 1e8;
long long int myMax(long long int x, long long int y) {
  return (x > y ? x : y);
}
int main() {
  INF *= INF;
  int i, j, n, m;
  long long int ans;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) {
    for (j = 1; j <= m; j++) {
      scanf("%lld", &a[i][j]);
    }
    sm[i][0] = 0;
    for (j = 1; j <= m; j++) {
      sm[i][j] = sm[i][j - 1] + a[i][j];
    }
    sm[i][0] = sm[i][m + 1] = -INF;
  }
  dp[0][0] = dp[0][m + 1] = -INF;
  for (j = m; j > 0; j--) dp[0][j] = myMax(dp[0][j + 1], sm[0][j]);
  for (i = 1; i < n; i++) {
    dp[i][0] = dp[i][m + 1] = -INF;
    if (i & 1) {
      for (j = 1; j <= m; j++) {
        dp[i][j] = myMax(dp[i][j - 1], dp[i - 1][j + 1] + sm[i][j]);
      }
    } else {
      for (j = m; j > 0; j--) {
        dp[i][j] = myMax(dp[i][j + 1], dp[i - 1][j - 1] + sm[i][j]);
      }
    }
  }
  ans = -INF;
  for (j = 1; j <= m; j++) {
    ans = myMax(ans, dp[n - 1][j]);
  }
  printf("%lld\n", ans);
  return 0;
}
