#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int arr[1509][1509];
long long dp[1509], pre[100009], suf[100009];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &arr[i][j]);
  for (int i = 1; i <= m; i++) dp[i] = dp[i - 1] + arr[1][i];
  for (int i = 2; i <= n; i++) {
    pre[0] = suf[m + 1] = -1000000000007;
    for (int j = 1; j <= m; j++) pre[j] = max(pre[j - 1], dp[j]);
    for (int j = m; j >= 1; j--) suf[j] = max(suf[j + 1], dp[j]);
    long long cur = 0;
    if (i & 1) {
      dp[1] = -1000000000007;
      cur = arr[i][1];
      for (int j = 2; j <= m; j++) {
        cur += arr[i][j];
        dp[j] = pre[j - 1] + cur;
      }
    } else {
      dp[m] = -1000000000007;
      for (int j = 1; j < m; j++) {
        cur += arr[i][j];
        dp[j] = suf[j + 1] + cur;
      }
    }
  }
  long long ans = -1000000000007;
  for (int i = 1; i <= m; i++) umax(ans, dp[i]);
  printf("%lld\n", ans);
  return 0;
}
