#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  scanf("%d %d", &n, &m);
  vector<long long> d(m), r_max(m), l_max(m);
  vector<int> s(m);
  for (int row = 0; row < n; ++row) {
    scanf("%d", &s[0]);
    for (int i = 1; i < m; ++i) {
      scanf("%d", &s[i]);
      s[i] += s[i - 1];
    }
    if (row & 1) {
      for (int i = 0; i < m - 1; ++i) d[i] = s[i] + r_max[i + 1];
      d[m - 1] = -1e18;
    } else {
      for (int i = 1; i < m; ++i) d[i] = s[i] + l_max[i - 1];
      d[0] = -1e18;
    }
    l_max[0] = d[0];
    for (int i = 1; i < m; ++i) l_max[i] = max(d[i], l_max[i - 1]);
    r_max[m - 1] = d[m - 1];
    for (int i = m - 2; i >= 0; --i) r_max[i] = max(d[i], r_max[i + 1]);
  }
  cout << *max_element(d.begin(), d.end());
  return 0;
}
