#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int Max = 1000;
long long arr[1501][1501];
long long dp[1501][1501];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%lld", &arr[i][j]);
      dp[i][j] = INT64_MIN;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < m; j++) {
      arr[i][j] += arr[i][j - 1];
    }
  }
  for (int j = 0; j < m; j++) dp[0][j] = arr[0][j];
  int Lmax[n][m], Rmax[n][m];
  int maxind = 0;
  Lmax[0][0] = 0;
  long long maxsum = dp[0][0];
  for (int j = 1; j < m; j++) {
    Lmax[0][j] = maxind;
    if (dp[0][j] > maxsum) {
      maxsum = dp[0][j];
      maxind = j;
    }
  }
  Rmax[0][m - 1] = m - 1;
  maxind = m - 1;
  maxsum = dp[0][m - 1];
  for (int j = m - 2; j >= 0; j--) {
    Rmax[0][j] = maxind;
    if (dp[0][j] > maxsum) {
      maxsum = dp[0][j];
      maxind = j;
    }
  }
  int alt = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (alt == 0 && j == 0 || alt == 1 && j == m - 1) continue;
      if (alt == 0) {
        dp[i][j] = arr[i][j] + dp[i - 1][Lmax[i - 1][j]];
      } else {
        dp[i][j] = arr[i][j] + dp[i - 1][Rmax[i - 1][j]];
      }
    }
    int maxind = 0;
    Lmax[i][0] = 0;
    long long maxsum = dp[i][0];
    for (int j = 1; j < m; j++) {
      Lmax[i][j] = maxind;
      if (dp[i][j] > maxsum) {
        maxsum = dp[i][j];
        maxind = j;
      }
    }
    Rmax[i][m - 1] = m - 1;
    maxind = m - 1;
    maxsum = dp[i][m - 1];
    for (int j = m - 2; j >= 0; j--) {
      Rmax[i][j] = maxind;
      if (dp[i][j] > maxsum) {
        maxsum = dp[i][j];
        maxind = j;
      }
    }
    alt ^= 1;
  }
  long long ans = INT64_MIN;
  for (int j = 0; j < m; j++) {
    ans = max(ans, dp[n - 1][j]);
  }
  printf("%lld\n", ans);
}
