#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  long long dp[m + 2];
  int now = 0;
  int c, sum = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d", &c);
    sum += c;
    dp[i] = sum;
  }
  dp[0] = -2147483647;
  long long ans = -2147483647;
  long long mm[m + 2];
  for (int i = m - 1; i >= 0; i--) {
    if (i == m - 1)
      mm[i] = dp[i];
    else
      mm[i] = max(dp[i], mm[i + 1]);
  }
  for (int i = 1; i < n; i++) {
    sum = 0;
    now = 1 - now;
    for (int j = 0; j < m; j++) {
      scanf("%d", &c);
      sum += c;
      dp[j] = sum;
    }
    for (int j = 0; j < m; j++) {
      if (i % 2 == 1) {
        if (j < m - 1) {
          dp[j] += mm[j + 1];
        } else if (j == m - 1) {
          dp[j] = -2147483647;
        }
      } else {
        if (j == 0)
          dp[j] = -2147483647;
        else {
          dp[j] += mm[j - 1];
        }
      }
      if (i == n - 1) {
        ans = max(ans, dp[j]);
      }
    }
    if (i % 2 == 0) {
      for (int j = m - 1; j >= 0; j--) {
        if (j == m - 1)
          mm[j] = dp[j];
        else
          mm[j] = max(dp[j], mm[j + 1]);
      }
    } else {
      for (int j = 0; j < m; j++) {
        if (j == 0)
          mm[j] = dp[j];
        else
          mm[j] = max(dp[j], mm[j - 1]);
      }
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
