#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
mt19937 rnd(
    std::chrono::high_resolution_clock::now().time_since_epoch().count());
void ProdamGaraje() {
  vector<long long> a[2000];
  long long m, n;
  cin >> n >> m;
  for (long long i = 0; i < n; ++i) {
    a[i].push_back(0);
    for (long long j = 0; j < m; ++j) {
      long long x;
      cin >> x;
      a[i].push_back(x + (a[i][(int)a[i].size() - 1]));
    }
  }
  for (long long i = m - 1; i >= 1; --i) {
    a[0][i] = max(a[0][i], a[0][i + 1]);
  }
  for (long long i = 1; i < n; ++i) {
    if (i % 2 == 1) {
      for (long long j = 1; j < m; ++j) {
        a[i][j] += a[i - 1][j + 1];
      }
      for (long long j = 2; j < m + 1; ++j) a[i][j] = max(a[i][j], a[i][j - 1]);
    } else {
      for (long long j = m; j >= 2; --j) {
        a[i][j] += a[i - 1][j - 1];
      }
      for (long long j = m - 1; j >= 1; --j)
        a[i][j] = max(a[i][j], a[i][j + 1]);
    }
  }
  if (n % 2 == 0) {
    cout << a[n - 1][m - 1];
  } else {
    cout << a[n - 1][2];
  }
}
void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  for (int i = 0; i < b; i++) {
    int x;
    cin >> x;
    int y;
    cin >> y;
  }
  for (int i = 0; i < c; i++) {
    string s;
    cin >> s;
    int x;
    cin >> x;
    for (int j = 0; j < x; j++) {
      int t;
      cin >> t;
    }
  }
  for (int i = 0; i < c; i++) {
    string s;
    cin >> s;
    int x;
    cin >> x;
    for (int j = 0; j < x; j++) {
      int t;
      cin >> t;
    }
  }
  int ans = rnd() % 2;
  if (ans)
    cout << "YES";
  else
    cout << "NO";
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) ProdamGaraje();
}
