#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e18 + 10;
const int N = 1510;
int n, m;
int a[N][N];
long long dp[2][N];
long long sum[N], myleft[N], myright[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", a[i] + j);
    }
  }
  dp[0][0] = a[0][0];
  for (int j = 1; j < m; ++j) {
    dp[0][j] = dp[0][j - 1] + a[0][j];
  }
  myleft[0] = dp[0][0];
  for (int j = 1; j < m; ++j) {
    myleft[j] = max(myleft[j - 1], dp[0][j]);
  }
  myright[m - 1] = dp[0][m - 1];
  for (int j = m - 2; j >= 0; --j) {
    myright[j] = max(myright[j + 1], dp[0][j]);
  }
  for (int i = 1; i < n; ++i) {
    sum[0] = a[i][0];
    for (int j = 1; j < m; ++j) sum[j] = sum[j - 1] + a[i][j];
    for (int j = 0; j < m; ++j) {
      dp[i & 1][j] = -INF;
      if (i & 1) {
        if (j + 1 < m) dp[i & 1][j] = myright[j + 1] + sum[j];
      } else {
        if (j - 1 >= 0) dp[i & 1][j] = myleft[j - 1] + sum[j];
      }
    }
    myleft[0] = dp[i & 1][0];
    for (int j = 1; j < m; ++j) myleft[j] = max(myleft[j - 1], dp[i & 1][j]);
    myright[m - 1] = dp[i & 1][m - 1];
    for (int j = m - 2; j >= 0; --j)
      myright[j] = max(myright[j + 1], dp[i & 1][j]);
  }
  long long ans = -INF;
  for (int j = 0; j < m; ++j) ans = max(ans, dp[(n - 1) & 1][j]);
  printf("%lld\n", ans);
  return 0;
}
