#include <bits/stdc++.h>
using namespace std;
const long long oo = 1000000000000LL;
int a[1500 + 10][1500 + 10] = {0};
long long s[1500 + 10][1500 + 10] = {0}, f[1500 + 10][1500 + 10] = {0};
long long l[1500 + 10][1500 + 10] = {0}, r[1500 + 10][1500 + 10] = {0};
int main() {
  int n, m;
  int i, j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) {
      scanf("%d", &a[i][j]);
      s[i][j] = s[i][j - 1] + a[i][j];
    }
  for (j = 1; j <= m; ++j) f[1][j] = s[1][j];
  l[1][0] = -oo, r[1][m + 1] = -oo;
  for (j = 1; j <= m; ++j)
    l[1][j] = ((l[1][j - 1]) > (f[1][j]) ? (l[1][j - 1]) : (f[1][j]));
  for (j = m; j >= 1; --j)
    r[1][j] = ((r[1][j + 1]) > (f[1][j]) ? (r[1][j + 1]) : (f[1][j]));
  for (i = 2; i <= n; ++i) {
    for (j = 1; j <= m; ++j) {
      if (i & 1)
        f[i][j] = l[i - 1][j - 1] + s[i][j];
      else
        f[i][j] = r[i - 1][j + 1] + s[i][j];
    }
    l[i][0] = -oo, r[i][m + 1] = -oo;
    for (j = 1; j <= m; ++j)
      l[i][j] = ((l[i][j - 1]) > (f[i][j]) ? (l[i][j - 1]) : (f[i][j]));
    for (j = m; j >= 1; --j)
      r[i][j] = ((r[i][j + 1]) > (f[i][j]) ? (r[i][j + 1]) : (f[i][j]));
  }
  cout << l[n][m] << endl;
  return (0);
}
