#include <bits/stdc++.h>
using namespace std;
long long dyn[1501][1501];
int a[1501][1501];
int n, m;
long long rec(int cur, int last) {
  if (dyn[cur][last] != (1LL << 63)) return dyn[cur][last];
  if (cur == n) return dyn[cur][last] = 0;
  long long res = (1LL << 63) + 1LL;
  int i;
  if (cur % 2 == 0) {
    if (last == m - 1) return dyn[cur][last] = res;
    res = max(res, rec(cur, last + 1));
    res = max(res, (long long)a[cur][last + 1] + rec(cur + 1, last + 1));
  } else {
    if (last == 0) return dyn[cur][last] = res;
    res = max(res, rec(cur, last - 1));
    res = max(res, (long long)a[cur][last - 1] + rec(cur + 1, last - 1));
  }
  return dyn[cur][last] = res;
}
int main() {
  int i, j;
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; ++i)
    for (j = 0; j < m; ++j) {
      scanf("%d", &a[i][j]);
      dyn[i][j] = (1LL << 63);
    }
  for (i = 0; i < n; ++i)
    for (j = 1; j < m; ++j) a[i][j] += a[i][j - 1];
  cout << rec(0, 0) << endl;
  return 0;
}
