#include <bits/stdc++.h>
using namespace std;
int n, m;
int w[2000][2000], a[2000][2000];
long long d[2000][2000], s[2000][2000];
long long get(int u, int l) {
  if (u == n + 1) return 0;
  if (w[u][l]) return d[u][l];
  d[u][l] = -(1ll << 40);
  w[u][l] = 1;
  if (u & 1) {
    if (l < m) d[u][l] = max(d[u][l], get(u, l + 1));
    if (l) d[u][l] = max(d[u][l], get(u + 1, l - 1) + s[u][l]);
  } else {
    if (l) d[u][l] = max(d[u][l], get(u, l - 1));
    if (l) d[u][l] = max(d[u][l], get(u + 1, l + 1) + s[u][l]);
  }
  return d[u][l];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) s[i][j] = s[i][j - 1] + a[i][j];
  cout << get(1, 0) << endl;
  return 0;
}
