#include <bits/stdc++.h>
using namespace std;
long long sum[1505][1505];
long long dp[1505][1505];
long long Max(long long a, long long b) { return (a > b ? a : b); }
int main() {
  int n, m;
  int i, j, k;
  while (scanf("%d %d", &n, &m) != EOF) {
    int x;
    for (i = 1; i <= n; i++) {
      sum[i][0] = 0;
      for (j = 1; j <= m; j++) {
        scanf("%d", &x);
        sum[i][j] = sum[i][j - 1] + x;
      }
    }
    for (j = 0; j <= m; j++) dp[1][j] = 0;
    for (i = 1; i <= n; i++) {
      if (i % 2 == 0) {
        for (j = 1; j < m; j++) dp[i][j] = dp[i - 1][j + 1] + sum[i][j];
        for (j = 2; j < m; j++) dp[i][j] = Max(dp[i][j], dp[i][j - 1]);
      } else {
        for (j = 2; j <= m; j++) dp[i][j] = dp[i - 1][j - 1] + sum[i][j];
        for (j = m - 1; j > 1; j--) dp[i][j] = Max(dp[i][j], dp[i][j + 1]);
      }
    }
    if (n % 2 == 1)
      cout << dp[n][2] << endl;
    else
      cout << dp[n][m - 1] << endl;
  }
  return 0;
}
