#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1500 + 100;
const long long inf =
    (long long)(1000 * 1000 * 1000) * (long long)(1000 * 1000);
long long a[2][MAX_N];
long long s[MAX_N];
int n, m, x;
int main() {
  scanf("%d%d", &n, &m);
  int t = 0;
  for (int j = 1; j <= m; j++) {
    scanf("%d", &x);
    a[t][j] = (long long)(x);
    a[t][j] += a[t][j - 1];
  }
  for (int i = 1; i < n; i++) {
    t = !t;
    for (int j = 1; j <= m; j++) {
      scanf("%d", &x);
      s[j] = (long long)(x);
      s[j] += s[j - 1];
    }
    if (t == 1) {
      a[t][m] = -inf;
      long long best = a[!t][m];
      for (int j = m - 1; j >= 1; j--) {
        a[t][j] = best + s[j];
        if (a[!t][j] > best) best = a[!t][j];
      }
    } else {
      a[t][1] = -inf;
      long long best = a[!t][1];
      for (int j = 2; j <= m; j++) {
        a[t][j] = best + s[j];
        if (a[!t][j] > best) best = a[!t][j];
      }
    }
  }
  long long ans = -inf;
  for (int j = 1; j <= m; j++)
    if (a[t][j] > ans) ans = a[t][j];
  cout << ans << endl;
  return 0;
}
