#include <bits/stdc++.h>
using namespace std;
int const lim = 3000 + 4;
long long dp[lim + 3][lim + 3], inp[lim + 3][lim + 3], pre[lim + 3][lim + 3];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      scanf("%lld", &inp[i][j]), pre[i][j] = pre[i][j - 1] + inp[i][j],
                                 dp[i][j] = -LONG_LONG_MAX / 2;
  for (int i = 1; i <= n; i++) {
    if (i % 2 == 0) {
      for (int j = 1; j < m; j++) {
        dp[i][j] = max(dp[i][j], dp[i - 1][j + 1] + pre[i][j]);
        if (j != 1) dp[i][j] = max(dp[i][j], dp[i][j - 1]);
      }
    } else {
      for (int j = m; j > 1; j--) {
        dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + pre[i][j]);
        if (j != m) dp[i][j] = max(dp[i][j], dp[i][j + 1]);
      }
    }
  }
  if (n == 1)
    cout << max(inp[n][1], dp[n][2]);
  else if (n % 2 == 1)
    cout << dp[n][2] << endl;
  else
    cout << dp[n][m - 1] << endl;
}
