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