#include <bits/stdc++.h>
long long int a[1500][1500];
using namespace std;
int main() {
  int n, m;
  scanf("%i", &n);
  scanf("%i", &m);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%i", &x);
    a[i][0] = x;
    for (int j = 1; j < m; j++) {
      scanf("%i", &x);
      a[i][j] = a[i][j - 1] + x;
    }
  }
  bool sign = n % 2;
  const long long int bad = -1000000000000;
  if (sign) {
    for (int j = m - 2; j >= 0; j--)
      if (a[n - 1][j] < a[n - 1][j + 1]) a[n - 1][j] = a[n - 1][j + 1];
  } else {
    for (int j = 1; j <= m; j++)
      if (a[n - 1][j] < a[n - 1][j - 1]) a[n - 1][j] = a[n - 1][j - 1];
  }
  for (int i = n - 2; i >= 0; i--) {
    if (sign) {
      a[i][m - 1] = bad;
      a[i][0] = a[i][0] + a[i + 1][1];
      for (int j = 1; j < m - 1; j++) {
        a[i][j] = a[i][j] + a[i + 1][j + 1] > a[i][j - 1]
                      ? a[i][j] + a[i + 1][j + 1]
                      : a[i][j - 1];
      }
    } else {
      a[i][m - 1] = a[i + 1][m - 2] + a[i][m - 1];
      a[i][0] = bad;
      for (int j = m - 2; j > 0; j--) {
        a[i][j] = a[i][j] + a[i + 1][j - 1] > a[i][j + 1]
                      ? a[i][j] + a[i + 1][j - 1]
                      : a[i][j + 1];
      }
    }
    sign = !sign;
  }
  long long int max;
  if (sign)
    max = a[0][1];
  else
    max = a[0][m - 2];
  cout << max;
  return 0;
}
