#include <bits/stdc++.h>
using namespace std;
int n, m, x;
long long f[1510], g[1510];
long long sum[1510];
int main() {
  memset(f, 0, sizeof(f));
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    sum[0] = x;
    for (int j = 1; j < m; ++j) {
      scanf("%d", &x);
      sum[j] = sum[j - 1] + x;
    }
    if (i == 0) {
      for (int j = 0; j < m; ++j) f[j] = sum[j];
    } else if ((i & 1) == 1) {
      long long cm = f[m - 1];
      for (int j = m - 2; j >= 0; --j) {
        g[j] = sum[j] + cm;
        cm = max(cm, f[j]);
      }
      for (int j = 0; j < m - 1; ++j) f[j] = g[j];
    } else {
      long long cm = f[0];
      for (int j = 1; j < m; ++j) {
        g[j] = sum[j] + cm;
        cm = max(cm, f[j]);
      }
      for (int j = 1; j < m; ++j) f[j] = g[j];
    }
  }
  long long ans = -9999999999999999ll;
  if ((n & 1) == 0) {
    for (int i = 0; i < m - 1; ++i) ans = max(f[i], ans);
  } else {
    for (int i = 1; i < m; ++i) ans = max(f[i], ans);
  }
  cout << ans << endl;
  return 0;
}
