#include <bits/stdc++.h>
using namespace std;
int t[1601][1601];
long long dm[1601][1601];
long long sum[1601][1601];
const long long inf = (long long)1e18;
int n, m;
long long tmp[1601];
int main() {
  scanf("%d%d\n", &n, &m);
  for (int i = 0; i < n; ++i) {
    sum[i][0] = 0;
    for (int j = 0; j < m; ++j) {
      scanf("%d", &(t[i][j + 1]));
      sum[i][j + 1] = sum[i][j] + (long long)t[i][j + 1];
    }
    scanf("\n");
  }
  dm[0][0] = -inf;
  for (int i = 0; i <= m; ++i) dm[0][i] = sum[0][i];
  for (int i = 1; i < n; ++i) {
    if (i % 2 == 1) {
      tmp[1] = dm[i - 1][m];
      for (int j = m - 1; j > 1; --j)
        tmp[m - j + 1] = max(dm[i - 1][j], tmp[m - j]);
      for (int j = 1; j < m; ++j) {
        dm[i][j] = tmp[m - j] + sum[i][j];
      }
      dm[i][m] = -inf;
      dm[i][0] = -inf;
    } else {
      tmp[1] = dm[i - 1][0];
      for (int j = 1; j < m; ++j) tmp[j + 1] = max(dm[i - 1][j], tmp[j]);
      for (int j = m; j > 0; --j) {
        dm[i][j] = tmp[j] + sum[i][j];
      }
      dm[i][0] = -inf;
    }
  }
  long long mn = -inf;
  for (int i = 1; i <= m; ++i) mn = max(mn, dm[n - 1][i]);
  cout << mn;
}
