#include <bits/stdc++.h>
using namespace std;
int a[1510][1510];
long long dp[1510][1510];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", a[i] + j);
  for (int i = 1; i <= n; i++) {
    if (i & 1) {
      long long s = 0, big = -(1LL << 60);
      ;
      for (int j = 1; j <= m; j++) {
        s += a[i][j];
        dp[i][j] = s + big;
        big = max(big, dp[i - 1][j]);
      }
    } else {
      long long s = 0, big = -(1LL << 60);
      ;
      for (int j = 1; j <= m; j++) s += a[i][j];
      for (int j = m; j > 0; j--) {
        dp[i][j] = s + big;
        s -= a[i][j];
        big = max(big, dp[i - 1][j]);
      }
    }
  }
  long long ans = -(1LL << 60);
  ;
  for (int i = 1; i <= m; i++) ans = max(ans, dp[n][i]);
  printf("%I64d\n", ans);
  return 0;
}
