#include <bits/stdc++.h>
using namespace std;
long long dp[1503][1503];
long long max1[1503][1503];
long long max2[1503][1503];
long long ps[1503][1503];
int n, m;
int AdjList[1503][1503];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= m + 1; j++) {
      dp[i][j] = -1e9;
      max1[i][j] = -1e9;
      max2[i][j] = -1e9;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> AdjList[i][j];
      ps[i][j] = ps[i][j - 1] + AdjList[i][j];
      if (i == 1) {
        dp[i][j] = ps[i][j];
        max1[i][j] = max(max1[i][j - 1], ps[i][j]);
      }
    }
    if (i == 1) {
      for (int j = m; j > 0; j--) max2[i][j] = max(max2[i][j + 1], ps[i][j]);
    }
  }
  for (int i = 2; i <= n; i++) {
    if (i & 1) {
      for (int j = 1; j <= m; j++) {
        dp[i][j] = ps[i][j] + max1[i - 1][j - 1];
      }
      for (int j = m; j > 0; j--) max2[i][j] = max(max2[i][j + 1], dp[i][j]);
    } else {
      for (int j = 1; j < m; j++) {
        dp[i][j] = ps[i][j] + max2[i - 1][j + 1];
      }
      for (int j = 1; j < m; j++) max1[i][j] = max(max1[i][j - 1], dp[i][j]);
    }
  }
  long long ans = -1e9;
  for (int j = 0; j <= m; j++) {
    ans = max(ans, dp[n][j]);
  }
  cout << ans;
}
