#include <bits/stdc++.h>
using namespace std;
long long x[1501][1501], dp[1501][1501], s[1501][1501], ms1[1501][1501],
    ms2[1501][1501];
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%I64d", &x[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) s[i][j] = s[i][j - 1] + x[i][j];
  for (int i = 1; i <= n; i++) {
    if (i % 2 == 1)
      for (int j = 2; j <= m; j++) dp[i][j] = s[i][j] + ms1[i - 1][j - 1];
    else
      for (int j = 1; j < m; j++) dp[i][j] = s[i][j] + ms2[i - 1][j + 1];
    ms1[i][0] = -1000000001;
    ms2[i][m + 1] = -1000000001;
    for (int j = 1; j <= m; j++) ms1[i][j] = max(ms1[i][j - 1], dp[i][j]);
    for (int j = m; j >= 1; j--) ms2[i][j] = max(ms2[i][j + 1], dp[i][j]);
  }
  long long ans = -100000000000000000ll;
  if (n % 2 == 1)
    for (int i = 2; i <= m; i++) ans = max(ans, dp[n][i]);
  else
    for (int i = 1; i < m; i++) ans = max(ans, dp[n][i]);
  printf("%I64d", ans);
}
