#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n, m;
  cin >> n >> m;
  long long num[n][m], dp[n + 7][m + 7], pref[n + 7][m + 7], suff[n + 7][m + 7];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) cin >> num[i][j];
  }
  for (long long i = 0; i < n + 7; i++) {
    for (long long j = 0; j < m + 7; j++) {
      dp[i][j] = 0;
      pref[i][j] = -INF;
      suff[i][j] = -INF;
    }
  }
  for (long long j = 1; j <= m; j++) {
    dp[0][j] = dp[0][j - 1] + num[0][j - 1];
  }
  for (long long j = 1; j <= m; j++) pref[0][j] = max(dp[0][j], pref[0][j - 1]);
  for (long long j = m; j >= 1; j--) suff[0][j] = max(dp[0][j], suff[0][j + 1]);
  for (long long i = 1; i < n; i++) {
    long long sum = 0;
    for (long long j = 1; j <= m; j++) {
      sum += num[i][j - 1];
      if (i % 2 == 0)
        dp[i][j] = sum + pref[i - 1][j - 1];
      else
        dp[i][j] = sum + suff[i - 1][j + 1];
    }
    for (long long j = 1; j <= m; j++)
      pref[i][j] = max(dp[i][j], pref[i][j - 1]);
    for (long long j = m; j >= 1; j--)
      suff[i][j] = max(dp[i][j], suff[i][j + 1]);
  }
  long long ans = -INF;
  for (long long j = 1; j <= m; j++) ans = max(ans, dp[n - 1][j]);
  cout << ans << "\n";
  return 0;
}
