#include <bits/stdc++.h>
using namespace std;
const long long INFINITE = 0x3f3f3f3f3f3f3f3fLL;
long long v[1500][1500];
int m, n;
long long vsum[1500][1501];
long long memo[1500][1501];
bool mark[1500][1501];
long long f(int i, int last) {
  if (i >= m) return 0;
  long long& best = memo[i][last];
  if (mark[i][last]) return best;
  best = -INFINITE, mark[i][last] = true;
  if (i % 2 == 0) {
    best = max(best, f(i + 1, last + 1) + vsum[i][last + 1]);
    if (last < n - 1) best = max(best, f(i, last + 1));
  } else {
    best = max(best, f(i + 1, last - 1) + vsum[i][last - 1]);
    if (last > 2) best = max(best, f(i, last - 1));
  }
  return best;
}
int main() {
  scanf("%d %d", &m, &n);
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) scanf("%lld", &v[i][j]);
    vsum[i][0] = 0;
    for (int j = 0; j < n; ++j) vsum[i][j + 1] = vsum[i][j] + v[i][j];
  }
  memset(mark, false, sizeof(mark));
  printf("%lld\n", f(0, 1));
  return 0;
}
