#include <bits/stdc++.h>
using namespace std;
long long int M[2000][2000], S[2000][2000], mayor[2000][2000];
int main() {
  long long int a, n, m, i, j, r;
  scanf("%I64d %I64d", &n, &m);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      scanf("%I64d", &a);
      if (j == 0) {
        S[i][j] = a;
      } else {
        S[i][j] = S[i][j - 1] + a;
      }
    }
  }
  for (i = 0; i <= n; i++)
    for (j = 0; j <= m; j++) mayor[i][j] = 0;
  for (i = n - 1; i >= 0; i--) {
    if (i % 2 == 0) {
      for (j = m - 1; j >= 1; j--) {
        M[i][j] = S[i][j] + mayor[i + 1][j - 1];
        if (j == m - 1)
          mayor[i][j] = M[i][j];
        else
          mayor[i][j] = max(mayor[i][j + 1], M[i][j]);
      }
    } else {
      for (j = 0; j < m - 1; j++) {
        M[i][j] = S[i][j] + mayor[i + 1][j + 1];
        if (j == 0)
          mayor[i][j] = M[i][j];
        else
          mayor[i][j] = max(mayor[i][j - 1], M[i][j]);
      }
    }
  }
  r = 0;
  for (j = 1; j < m; j++) {
    if (j == 1)
      r = M[0][j];
    else
      r = max(M[0][j], r);
  }
  printf("%I64d", r);
  return 0;
}
