#include <bits/stdc++.h>
using namespace std;
int n, m;
int sum[1505][1505];
long long dp[1505][1505];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    sum[i][0] = 0;
    for (int j = 1; j <= m; j++) {
      scanf("%d", &sum[i][j]);
      sum[i][j] += sum[i][j - 1];
    }
  }
  for (int i = 1; i <= m; i++) dp[1][i] = sum[1][i];
  for (int i = 2; i <= n; i++) {
    if (i % 2 == 1) {
      long long mx = dp[i - 1][1];
      for (int j = 2; j <= m; j++) {
        dp[i][j] = mx + sum[i][j];
        mx = max(mx, dp[i - 1][j]);
      }
    } else {
      long long mx = dp[i - 1][m];
      for (int j = m - 1; j >= 1; j--) {
        dp[i][j] = mx + sum[i][j];
        mx = max(mx, dp[i - 1][j]);
      }
    }
  }
  long long ret = -(1 << 30) * 1LL * (1 << 30);
  for (int i = 1 + n % 2; i <= m - (1 - n % 2); i++) ret = max(ret, dp[n][i]);
  printf("%I64d\n", ret);
}
