#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<vector<long long>> arr(n, vector<long long>(m));
  vector<long long> comp;
  comp.reserve(n * m);
  for (long long i = 0; i < n; ++i) {
    long long sum = 0;
    for (long long j = 0; j < m; ++j) {
      cin >> arr[i][j];
    }
  }
  vector<long long> memo(m, -inf);
  for (long long i = 0; i < n; ++i) {
    vector<long long> prefixMax(m, -inf);
    prefixMax[0] = memo[0];
    for (long long j = 1; j < m; ++j) {
      prefixMax[j] = max(prefixMax[j - 1], memo[j]);
    }
    vector<long long> suffixMax(m, -inf);
    suffixMax[m - 1] = memo[m - 1];
    for (long long j = m - 2; j >= 0; --j) {
      suffixMax[j] = max(suffixMax[j + 1], memo[j]);
    }
    vector<long long> newMemo(m, -inf);
    long long sum = 0;
    for (long long j = 0; j < m; ++j) {
      sum += arr[i][j];
      if (i % 2 == 1) {
        if (j + 1 < m) newMemo[j] = max(newMemo[j], sum + suffixMax[j + 1]);
      } else {
        if (i) {
          if (j) newMemo[j] = max(newMemo[j], sum + prefixMax[j - 1]);
        } else {
          newMemo[j] = max(newMemo[j], sum);
        }
      }
    }
    memo.swap(newMemo);
  }
  long long res = -inf;
  for (long long j = 0; j < m; ++j) {
    res = max(res, memo[j]);
  }
  cout << res << '\n';
}
