#include <bits/stdc++.h>
using namespace std;
long long dp[2][1505];
long long data[1505][1505];
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < ((long long)n); i++)
    for (long long j = 0; j < ((long long)m); j++) scanf("%I64d", &data[i][j]);
  for (long long i = 0; i < ((long long)n); i++)
    for (long long j = 0; j < ((long long)m - 1); j++)
      data[i][j + 1] += data[i][j];
  for (long long i = 0; i < ((long long)n); i++) {
    if (i % 2) {
      for (long long j = 0; j < ((long long)m - 1); j++)
        data[i][j] += data[i - 1][j + 1];
      data[i][m - 1] = -(1 << 25);
      for (long long j = 0; j < ((long long)m - 2); j++)
        data[i][j + 1] = max(data[i][j + 1], data[i][j]);
    } else {
      if (i)
        for (long long j = 0; j < ((long long)m - 1); j++)
          data[i][j + 1] += data[i - 1][j];
      if (i) data[i][0] = -(1 << 25);
      for (long long j = m - 2; 0 <= j; j--)
        data[i][j] = max(data[i][j + 1], data[i][j]);
    }
  }
  long long best = -(1 << 25);
  for (long long i = 0; i < ((long long)m); i++)
    best = max(best, data[n - 1][i]);
  cout << best << endl;
}
