#include <bits/stdc++.h>
using namespace std;
const int INFI = (1 << 30);
const long long INFL = (1LL << 62);
long long dp[1501][1501];
long long v[1501];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  deque<long long> d;
  for (int i = 1; i <= m; i++) {
    int x;
    scanf("%d", &x);
    v[i] = x + v[i - 1];
    dp[1][i] = v[i];
    while (!d.empty() && v[i] > v[d.back()]) d.pop_back();
    d.push_back(i);
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int x;
      scanf("%d", &x);
      v[j] = x + v[j - 1];
    }
    if (i % 2) {
      d.clear();
      long long mx = dp[i - 1][1];
      for (int j = 2; j <= m; j++) {
        dp[i][j] = mx + v[j];
        while (!d.empty() && dp[i][j] > dp[i][d.back()]) d.pop_back();
        d.push_back(j);
        mx = max(dp[i - 1][j], mx);
      }
    } else {
      for (int j = 1; j < m; j++) {
        while (d.front() <= j) d.pop_front();
        dp[i][j] = dp[i - 1][d.front()] + v[j];
      }
    }
  }
  if (n % 2)
    printf("%I64d", *max_element(dp[n] + 2, dp[n] + m + 1));
  else
    printf("%I64d", *max_element(dp[n] + 1, dp[n] + m));
  return 0;
}
