#include <bits/stdc++.h>
using namespace std;
long long n, m, a[1777][1777], l[1777], b[1777];
void read(void) {
  cin >> n >> m;
  for (long long i = 1; i <= n; ++i)
    for (long long j = 1; j <= m; ++j) {
      cin >> a[i][j];
      a[i][j] += a[i][j - 1];
    }
}
void din(void) {
  b[m] = a[1][m];
  for (long long i = m - 1; i >= 1; --i) b[i] = max(b[i + 1], a[1][i]);
  for (long long i = 2; i <= n; ++i)
    if (i % 2 == 0) {
      l[1] = a[i][1] + b[2];
      for (long long j = 2; j < m; ++j)
        l[j] = max((a[i][j] + b[j + 1]), l[j - 1]);
    } else {
      b[m] = a[i][m] + l[m - 1];
      for (long long j = m - 1; j > 1; --j)
        b[j] = max(b[j + 1], (a[i][j] + l[j - 1]));
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  read();
  din();
  if (n % 2 == 0)
    cout << l[m - 1];
  else
    cout << b[2];
  return 0;
}
