#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  long long **a = new long long *[n];
  for (long long i = 0; i < n; i++) {
    a[i] = new long long[m];
    for (long long j = 0; j < m; j++) {
      int temp;
      scanf("%d", &temp);
      a[i][j] = (long long)temp;
    }
  }
  long long inf = 999999999;
  inf *= inf;
  long long **b = new long long *[n];
  for (long long i = 0; i < n; i++) {
    b[i] = new long long[m];
    for (long long j = 0; j < m; j++) b[i][j] = -inf;
  }
  long long **sum = new long long *[n];
  for (long long i = 0; i < n; i++) {
    sum[i] = new long long[m];
    for (long long j = 0; j < m; j++) sum[i][j] = 0;
  }
  for (long long i = 0; i < n; i++) sum[i][0] = a[i][0];
  for (long long i = 0; i < n; i++)
    for (long long j = 1; j < m; j++) sum[i][j] = sum[i][j - 1] + a[i][j];
  b[0][0] = a[0][0];
  for (long long i = 1; i < m; i++) b[0][i] = b[0][i - 1] + a[0][i];
  for (long long i = 1; i < n; i++) {
    long long ma1 = -inf;
    long long *ma2 = new long long[m];
    ma2[m - 1] = b[i - 1][m - 1];
    for (long long j = m - 2; j >= 0; j--)
      ma2[j] = max(ma2[j + 1], b[i - 1][j]);
    for (long long j = 0; j < m; j++) {
      if (i % 2 == 1) {
        if (j != m - 1) b[i][j] = max(b[i][j], ma2[j + 1] + sum[i][j]);
      } else {
        if (j != 0) {
          ma1 = max(ma1, b[i - 1][j - 1]);
          b[i][j] = max(b[i][j], ma1 + sum[i][j]);
        }
      }
    }
  }
  long long ans = -inf;
  for (long long i = 0; i < m; i++) ans = max(ans, b[n - 1][i]);
  cout << ans;
  return 0;
}
