#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e15;
int in[1501][1501];
long long r[2][1501], maxi[1501];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", in[i] + j);
    }
  }
  for (int i = 0; i <= m; ++i) r[0][i] = r[1][i] = 0;
  for (int j = 0, s = 0; j < m; ++j) {
    s += in[0][j];
    r[0][j] = s;
  }
  for (int i = 1; i < n; ++i) {
    int akt = i % 2, pre = akt ^ 1;
    if (akt) {
      maxi[m] = -INF;
      for (int j = m - 1; j >= 0; --j) {
        maxi[j] = max(maxi[j + 1], r[pre][j]);
      }
      long long s = 0;
      for (int j = 0; j + 1 < m; ++j) {
        s += in[i][j];
        r[akt][j] = s + maxi[j + 1];
      }
      r[akt][m - 1] = -INF;
    } else {
      r[akt][0] = -INF;
      long long best = r[pre][0], s = in[i][0];
      for (int j = 1; j < m; ++j) {
        s += in[i][j];
        r[akt][j] = s + best;
        best = max(best, r[pre][j]);
      }
    }
  }
  long long wynik = -INF;
  int akt = (n - 1) % 2;
  for (int j = 0; j < m; ++j) {
    wynik = max(wynik, r[akt][j]);
  }
  cout << wynik << "\n";
}
