#include <bits/stdc++.h>
using namespace std;
void print(vector<vector<long long> > &a) {
  for (size_t i = 0; i < a.size(); ++i) {
    for (size_t j = 0; j < a[i].size(); ++j) cout << a[i][j] << ' ';
    cout << endl;
  }
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<long long> > a(n);
  for (int i = 0; i < n; ++i) {
    a[i].assign(m, 0);
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
      if (j > 0) a[i][j] += a[i][j - 1];
    }
  }
  for (int j = m - 2; j >= 0; --j)
    if (a[0][j] < a[0][j + 1]) a[0][j] = a[0][j + 1];
  for (int i = 1; i < n; ++i)
    if ((i & 1) == 0) {
      for (int j = m - 1; j > 0; --j) {
        a[i][j] += a[i - 1][j - 1];
        if (j < m - 1 && a[i][j] < a[i][j + 1]) a[i][j] = a[i][j + 1];
      }
      a[i][0] = LLONG_MIN;
    } else {
      for (int j = 0; j < m - 1; ++j) {
        a[i][j] += a[i - 1][j + 1];
        if (j > 0 && a[i][j] < a[i][j - 1]) a[i][j] = a[i][j - 1];
      }
      a[i][m - 1] = LLONG_MIN;
    }
  cout << *max_element(a[n - 1].begin(), a[n - 1].end());
  return EXIT_SUCCESS;
}
