#include <bits/stdc++.h>
using namespace std;
const int M = 1505;
const long long INF = 0x3f3f3f3f3f3f3f3f;
long long dp[M][M];
int nu[M];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int i = 1; i <= m; i++) scanf("%d", &nu[i]);
    for (int i = 1; i <= m; i++) nu[i] += nu[i - 1];
    if (i & 1) {
      for (int j = 2; j <= m; j++)
        dp[i - 1][j] = max(dp[i - 1][j], dp[i - 1][j - 1]);
      for (int j = m; j > 1; j--) dp[i][j] = dp[i - 1][j - 1] + nu[j];
      dp[i][1] = -INF;
    } else {
      for (int j = m - 1; j >= 1; j--)
        dp[i - 1][j] = max(dp[i - 1][j], dp[i - 1][j + 1]);
      for (int j = 1; j < m; j++) dp[i][j] = dp[i - 1][j + 1] + nu[j];
      dp[i][m] = -INF;
    }
  }
  long long ans = -INF;
  for (int i = 1; i <= m; i++) ans = max(ans, dp[n][i]);
  printf("%lld\n", ans);
  return 0;
}
