#include <bits/stdc++.h>
using namespace std;
long long n, m, a[1505], dp[2][1505];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  scanf("%I64d%I64d", &n, &m);
  for (long long i = 1; i <= 1; ++i) {
    for (long long j = 1; j <= m; ++j) {
      scanf("%I64d", &a[j]);
      a[j] += a[j - 1];
    }
  }
  dp[0][m] = a[m];
  for (long long i = m - 1; i > 1; --i) dp[0][i] = max(a[i], dp[0][i + 1]);
  for (long long i = 2; i <= n; ++i) {
    for (long long j = 1; j <= m; ++j) {
      scanf("%I64d", &a[j]);
      a[j] += a[j - 1];
    }
    if (i % 2) {
      dp[1][m] = a[m] + dp[0][m - 1];
      for (long long j = m - 1; j > 1; --j)
        dp[1][j] = max(dp[1][j + 1], a[j] + dp[0][j - 1]);
    } else {
      dp[1][1] = a[1] + dp[0][2];
      for (long long j = 2; j < m; ++j)
        dp[1][j] = max(dp[1][j - 1], dp[0][j + 1] + a[j]);
    }
    for (long long j = 0; j <= m; ++j) dp[0][j] = dp[1][j];
  }
  if (n % 2)
    cout << dp[0][2];
  else
    cout << dp[0][m - 1];
  return 0;
}
