#include <bits/stdc++.h>
using namespace std;
long long int s[1510][1510] = {0};
long long int ms[1510][1510] = {0};
long long int a[1510][1510] = {0};
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      s[i][j] = a[i][j] + s[i][j - 1];
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i & 1) {
      ms[i][m] = s[i][m] + ms[i - 1][m - 1];
      for (int j = m - 1; j >= 1; j--) {
        ms[i][j] = max(ms[i][j + 1], s[i][j] + ms[i - 1][j - 1]);
      }
    } else {
      ms[i][1] = s[i][1] + ms[i - 1][2];
      for (int j = 2; j <= m; j++) {
        ms[i][j] = max(ms[i][j - 1], s[i][j] + ms[i - 1][j + 1]);
      }
    }
  }
  long long int m1 = -10000000000;
  if (n & 1) {
    for (int j = 2; j <= m; j++) {
      m1 = max(m1, ms[n][j]);
    }
  } else {
    for (int j = 1; j < m; j++) {
      m1 = max(m1, ms[n][j]);
    }
  }
  cout << m1;
  return 0;
}
