#include <bits/stdc++.h>
using namespace std;
int n, m, a[1501][1501], i, j, s[1501][1501];
long long d[1501][1501], maxs;
int main() {
  cin >> n >> m;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) cin >> a[i][j];
  for (i = 0; i < n; i++) s[i][0] = a[i][0];
  for (i = 0; i < n; i++)
    for (j = 1; j < m; j++) s[i][j] = s[i][j - 1] + a[i][j];
  for (i = 0; i < m; i++) d[0][i] = s[0][i];
  for (i = 1; i < n; i++)
    if (i % 2 == 0) {
      maxs = -1000000000;
      for (j = 0; j < m; j++) {
        d[i][j] = maxs + s[i][j];
        if (d[i - 1][j] > maxs) maxs = d[i - 1][j];
      }
    } else {
      maxs = -1000000000;
      for (j = m - 1; j >= 0; j--) {
        d[i][j] = maxs + s[i][j];
        if (d[i - 1][j] > maxs) maxs = d[i - 1][j];
      }
    }
  maxs = -1000000000;
  for (i = 0; i < m; i++)
    if (d[n - 1][i] > maxs) maxs = d[n - 1][i];
  cout << maxs;
  return 0;
}
