#include <bits/stdc++.h>
using namespace std;
long long n, m, i, mx, j;
long long S[1501][1501], M[1501][1501], DP1[1501][1501], DP2[1501][1501];
bool B[1501][1501], B1[1501][1501], B2[1501][1501];
long long solve(long long i, long long j);
long long dp2(long long i, long long j) {
  long long &res = DP2[i][j];
  if (!B2[i][j]) {
    res = solve(i, j);
    if (j + 1 < m) res = max(res, dp2(i, j + 1));
    B2[i][j] = 1;
  }
  return res;
}
long long dp1(long long i, long long j) {
  long long &res = DP1[i][j];
  if (!B1[i][j]) {
    res = solve(i, j);
    if (j) res = max(res, dp1(i, j - 1));
    B1[i][j] = 1;
  }
  return res;
}
long long solve(long long i, long long j) {
  long long &res = M[i][j];
  if (!B[i][j]) {
    if (i == n - 1)
      res = S[i][j];
    else if (i & 1)
      if (j + 1 < m)
        res = dp2(i + 1, j + 1) + S[i][j];
      else
        res = -1000000000000000000ll;
    else if (j - 1 >= 0)
      res = dp1(i + 1, j - 1) + S[i][j];
    else
      res = -1000000000000000000ll;
    B[i][j] = 1;
  }
  return res;
}
int main() {
  scanf("%I64d%I64d", &n, &m);
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      scanf("%I64d", &S[i][j]);
      if (j) S[i][j] += S[i][j - 1];
    }
  for (i = 0; i < m; i++)
    if (!i || solve(0, i) > mx) mx = solve(0, i);
  printf("%I64d", mx);
  return 0;
}
