#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, w, e, r, d[1500];
  long long t, *a = new long long[1500], *a1 = new long long[1500], *a2,
               s[1500];
  scanf("%d%d", &q, &w);
  for (e = 0; e < w; e++) a[e] = 0;
  for (e = 0; e < q; e++) {
    for (r = 0; r < w; r++) scanf("%d", &d[r]);
    if ((e & 1) == 0) {
      s[0] = a1[0] = -(((long long)1) << 50);
      for (r = 1; r < w; r++) s[r] = max(s[r - 1], a[r - 1]);
      t = d[0];
      for (r = 1; r < w; r++) {
        t += d[r];
        a1[r] = t + s[r];
      }
    } else {
      s[w - 1] = a1[w - 1] = -(((long long)1) << 50);
      for (r = w - 2; r >= 0; r--) s[r] = max(s[r + 1], a[r + 1]);
      t = 0;
      for (r = 0; r < w - 1; r++) {
        t += d[r];
        a1[r] = t + s[r];
      }
    }
    a2 = a;
    a = a1;
    a1 = a2;
  }
  t = -(((long long)1) << 50);
  for (r = 0; r < w; r++) t = max(t, a[r]);
  cout << t;
  return 0;
}
