#include <bits/stdc++.h>
using namespace std;
long long sum[1510][1510], n, m, dp[1510][1510];
pair<long long, int> dude[1510];
long long rec() {
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= m; j++) dp[i][j] = (long long)-1000000000000000000;
  dp[0][0] = (long long)-1000000000000000000;
  for (int p = 0; p <= n - 1; p++) {
    long long c = 0;
    for (int i = 0; i <= m - 1; i++) {
      c += sum[p][i];
      if (p % 2 == 0)
        dude[i] = make_pair(c + dp[p][i], i - 1);
      else
        dude[i] = make_pair(c + dp[p][i], i + 1);
    }
    sort(dude, dude + m, greater<pair<long long, int> >());
    if (p % 2 == 0) {
      int l = 0;
      for (int i = 0; i <= m - 1; i++) {
        for (int j = l; j <= dude[i].second; j++) dp[p + 1][j] = dude[i].first;
        l = max(l, dude[i].second + 1);
      }
    } else {
      int l = m - 1;
      for (int i = 0; i <= m - 1; i++) {
        for (int j = dude[i].second; j <= l; j++) dp[p + 1][j] = dude[i].first;
        l = min(l, dude[i].second - 1);
      }
    }
  }
  return dude[0].first;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i <= n - 1; i++)
    for (int j = 0; j <= m - 1; j++) cin >> sum[i][j];
  cout << rec() << endl;
  return 0;
}
