#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 3;
const long long inf = 1e18;
long long dp[2][MAXN];
int sum[MAXN][MAXN];
long long pref[2][MAXN];
int n, m;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  scanf("%d%d", &n, &m);
  for (auto i = 0; i != n; i++) {
    for (auto j = 0; j != m; j++) {
      scanf("%d", &sum[i][j]);
      if (j > 0) sum[i][j] += sum[i][j - 1];
    }
  }
  for (auto j = 0; j != m + 2; j++) pref[0][j] = 0;
  int tc = 1;
  for (auto i = 0; i != n; i++) {
    dp[tc][0] = -inf;
    dp[tc][m + 1] = -inf;
    for (auto j = 1; j != m + 1; j++) {
      int add = sum[i][j - 1];
      dp[tc][j] = add + ((tc == 1) ? pref[1 - tc][j - 1] : pref[1 - tc][j + 1]);
    }
    if (tc == 1) {
      pref[tc][m + 1] = -inf;
      for (auto j = m; j != 0; j--)
        pref[tc][j] = max(dp[tc][j], pref[tc][j + 1]);
    } else {
      pref[tc][0] = -inf;
      for (auto j = 1; j != m + 1; j++)
        pref[tc][j] = max(dp[tc][j], pref[tc][j - 1]);
    }
    tc = 1 - tc;
  }
  tc = 1 - tc;
  long long ans = -inf;
  for (auto j = 1; j != m + 1; j++) ans = max(ans, dp[tc][j]);
  printf("%lld", ans);
  return 0;
}
