#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1505;
long long row[MAXN];
long long dp[MAXN];
int main() {
  int n, m;
  long long ans;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%I64d", &(row[j]));
      if (j > 0) row[j] += row[j - 1];
    }
    if (i == 0) {
      dp[0] = row[0];
      for (int j = 1; j < m; j++) dp[j] = row[j];
    } else if (i % 2 == 0) {
      long long nowmax = dp[0];
      for (int j = 1; j < m; j++) {
        long long tem = dp[j];
        dp[j] = nowmax + row[j];
        nowmax = max(nowmax, tem);
      }
    } else {
      long long nowmax = dp[m - 1];
      for (int j = m - 2; j >= 0; j--) {
        long long tem = dp[j];
        dp[j] = nowmax + row[j];
        nowmax = max(nowmax, tem);
      }
    }
  }
  ans = LLONG_MIN;
  if (n % 2 == 0)
    for (int i = 0; i < m - 1; i++) ans = max(ans, dp[i]);
  else
    for (int i = 1; i < m; i++) ans = max(ans, dp[i]);
  printf("%I64d\n", ans);
  return 0;
}
