#include <bits/stdc++.h>
using namespace std;
long long s[1510][1510];
long long f[1510][1510];
int n, m, x;
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    memset(s, 0, sizeof(s));
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        scanf("%d", &x);
        if (j == 0)
          s[i][j] = x;
        else
          s[i][j] = s[i][j - 1] + x;
      }
    for (int j = 0; j < m; j++) f[0][j] = s[0][j];
    for (int i = 1; i < n; i++) {
      long long mx = -(0x3fffffffLL * 0x3fffffffLL);
      if (i & 1) {
        for (int j = m - 1; j >= 0; j--) {
          f[i][j] = s[i][j] + mx;
          mx = max(mx, f[i - 1][j]);
        }
      } else {
        for (int j = 0; j < m; j++) {
          f[i][j] = s[i][j] + mx;
          mx = max(mx, f[i - 1][j]);
        }
      }
    }
    long long ans = -(0x3fffffffLL * 0x3fffffffLL);
    for (int j = 0; j < m; j++)
      if (f[n - 1][j] > ans) ans = f[n - 1][j];
    cout << ans << endl;
  }
  return 0;
}
