#include <bits/stdc++.h>
using namespace std;
int s[1509][1509];
long long int dp[1509][1509];
int main() {
  int m, n, i, j;
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) scanf("%d", &s[i][j]);
  for (i = 1; i <= n; i++)
    for (j = 2; j <= m; j++) s[i][j] += s[i][j - 1];
  for (i = 0; i <= n + 4; i++)
    for (j = 0; j <= m + 4; j++) dp[i][j] = -(long long)(1 << 30);
  i = 1;
  for (j = 1; j <= m; j++) dp[1][j] = s[1][j];
  for (i = 2; i <= n; i++) {
    if ((i & 1) == 0) {
      long long cm = -(long long)(1 << 30);
      for (j = m; j > 0; j--) {
        dp[i][j] = cm + s[i][j];
        if (cm < dp[i - 1][j]) cm = dp[i - 1][j];
      }
    } else {
      long long cm = -(long long)(1 << 30);
      for (j = 1; j <= m; j++) {
        dp[i][j] = cm + s[i][j];
        if (cm < dp[i - 1][j]) cm = dp[i - 1][j];
      }
    }
  }
  cout << *max_element(dp[n] + 1, dp[n] + m + 1);
}
