#include <bits/stdc++.h>
using namespace std;
void Weapons19() {
  cout << fixed << setprecision(16);
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  Weapons19();
  long long int n, m;
  cin >> n >> m;
  long long int ans = -999999999;
  vector<vector<long long int>> v(n, vector<long long int>(m));
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) cin >> v[i][j];
    for (long long int j = 1; j < m; j++) v[i][j] += v[i][j - 1];
  }
  vector<long long int> pp(m);
  vector<vector<long long int>> dp(n, vector<long long int>(m));
  for (long long int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      dp[i] = v[i];
      dp[i][0] = -99999999;
      for (long long int j = 1; j < m; j++) dp[i][j] += pp[j - 1];
      pp = dp[i];
      for (long long int j = m - 2; j >= 0; j--) pp[j] = max(pp[j], pp[j + 1]);
    } else {
      dp[i] = v[i];
      for (long long int j = 0; j < m - 1; j++) dp[i][j] += pp[j + 1];
      dp[i][m - 1] = -99999999;
      pp = dp[i];
      for (long long int j = 1; j < m; j++) pp[j] = max(pp[j], pp[j - 1]);
    }
  }
  for (auto a : dp[n - 1]) ans = max(ans, a);
  cout << ans;
}
