#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int n;
int m;
int was[1501][1501];
long long res[1501][1501];
int s[1501][1501], g[1501][1501];
long long go(int i, int j) {
  if (i == n) return 0;
  if (j == -1 || j == m) return -1e15;
  if (was[i][j]) return res[i][j];
  was[i][j] = 1;
  res[i][j] = -1e15;
  if (i & 1) {
    res[i][j] = max(go(i, j - 1), go(i + 1, j + 1) + s[i][j]);
  } else {
    res[i][j] = max(go(i, j + 1), go(i + 1, j - 1) + s[i][j]);
  }
  return res[i][j];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &g[i][j]);
  for (int i = 0; i < n; i++) {
    s[i][0] = g[i][0];
    for (int j = 0; j + 1 < m; j++) s[i][j + 1] = s[i][j] + g[i][j + 1];
  }
  cout << go(0, 1) << endl;
  return 0;
}
