#include <bits/stdc++.h>
using namespace std;
const int maxn = 1505;
long long inf = 1ll << 60;
long long arr[maxn][maxn], dp[maxn][maxn], down[maxn][maxn], up[maxn][maxn],
    sum[maxn][maxn];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      scanf("%I64d", &dp[i][j]);
      sum[i][j] = dp[i][j];
      if (j) sum[i][j] += sum[i][j - 1];
    }
  for (int i = 0; i < n; i++) {
    if (i & 1) {
      up[i - 1][m - 1] = dp[i - 1][m - 1];
      dp[i][m - 1] = -inf;
      for (int j = m - 2; j >= 0; j--) {
        up[i - 1][j] = max(up[i - 1][j + 1], dp[i - 1][j]);
        dp[i][j] = up[i - 1][j + 1] + sum[i][j];
      }
    } else if (i == 0) {
      for (int j = 0; j < m; j++) dp[0][j] = sum[0][j];
    } else {
      down[i - 1][0] = dp[i - 1][0];
      dp[i][0] = -inf;
      for (int j = 1; j < m; j++) {
        down[i - 1][j] = max(dp[i - 1][j], down[i - 1][j - 1]);
        dp[i][j] = down[i - 1][j - 1] + sum[i][j];
      }
    }
  }
  long long ans = -inf;
  for (int j = 0; j < m; j++) ans = max(ans, dp[n - 1][j]);
  cout << ans;
  return 0;
}
