#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
vector<int> v[1505];
long long dp[1505][1505];
long long oo = 1000000000000000LL;
int main() {
  for (int i = 0; i < 1505; i++)
    for (int j = 0; j < 1505; j++) dp[i][j] = -oo;
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int a;
      scanf("%d", &a);
      v[i].push_back(a);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < (int)(v[i]).size(); j++) {
      v[i][j] += v[i][j - 1];
    }
  }
  for (int i = 1; i <= m; i++) {
    dp[0][i] = v[0][i - 1];
  }
  for (int j = m - 1; j >= 1; j--) {
    dp[0][j] = max(dp[0][j], dp[0][j + 1]);
  }
  bool f = false;
  for (int i = 1; i < n; i++) {
    if (f) {
      for (int j = 2; j <= m; j++) {
        dp[i][j] = dp[i - 1][j - 1] + v[i][j - 1];
      }
      for (int j = m - 1; j >= 1; j--) {
        dp[i][j] = max(dp[i][j], dp[i][j + 1]);
      }
    } else {
      for (int j = 1; j <= m; j++) {
        dp[i][j] = dp[i - 1][j + 1] + v[i][j - 1];
      }
      for (int j = 2; j <= m; j++) {
        dp[i][j] = max(dp[i][j], dp[i][j - 1]);
      }
    }
    f = !f;
  }
  long long res = -oo;
  for (int i = 1; i <= m; i++) {
    res = max(res, dp[n - 1][i]);
  }
  cout << res << endl;
  return 0;
}
