#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
long long mat[1505][1505], dp[1505][1505], sp[1505][1505];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> mat[i][j];
      dp[i][j] = -inf;
      sp[i][j] = sp[i][j - 1] + mat[i][j];
    }
  }
  long long ans = -inf, aux;
  for (int i = 1; i <= n; i++) {
    if (i % 2 == 1) {
      aux = dp[i - 1][1];
      for (int j = 2; j <= m; j++) {
        dp[i][j] = sp[i][j] + aux;
        aux = max(aux, dp[i - 1][j]);
        if (i == n) {
          ans = max(ans, dp[i][j]);
        }
      }
    } else {
      aux = dp[i - 1][m];
      for (int j = m - 1; j >= 1; j--) {
        dp[i][j] = sp[i][j] + aux;
        aux = max(aux, dp[i - 1][j]);
        if (i == n) {
          ans = max(ans, dp[i][j]);
        }
      }
    }
  }
  cout << ans;
  return 0;
}
