#include <bits/stdc++.h>
using namespace std;
int n, m;
int mas[2][1600];
long long pre[2][1600];
long long dyn[2][1600];
inline long long max(long long a, long long b) { return (a > b) ? a : b; }
int main() {
  scanf("%d%d", &n, &m);
  int pos = 0;
  for (int(j) = 0; (j) < (m); ++(j)) scanf("%d", &mas[pos][j]);
  dyn[pos][0] = pre[pos][0] = mas[pos][0];
  for (int(j) = (1); (j) < (m); ++(j))
    dyn[pos][j] = pre[pos][j] = pre[pos][j - 1] + mas[pos][j];
  pos = ((pos + 1) % 2);
  for (int(i) = (1); (i) < (n); ++(i)) {
    scanf("%d", &mas[pos][0]);
    pre[pos][0] = mas[pos][0];
    for (int(j) = (1); (j) < (m); ++(j)) {
      scanf("%d", &mas[pos][j]);
      pre[pos][j] = pre[pos][j - 1] + mas[pos][j];
    }
    if (i % 2 == 1) {
      dyn[pos][m - 1] = -1000000000000000LL;
      dyn[pos][m - 2] = dyn[((pos + 1) % 2)][m - 1] + pre[pos][m - 2];
      for (int j = m - 3; j >= 0; --j)
        dyn[pos][j] = max(dyn[pos][j + 1] - mas[pos][j + 1],
                          pre[pos][j] + dyn[((pos + 1) % 2)][j + 1]);
    } else {
      dyn[pos][0] = -1000000000000000LL;
      dyn[pos][1] = dyn[((pos + 1) % 2)][0] + pre[pos][1];
      for (int j = 2; j < m; ++j)
        dyn[pos][j] = max(dyn[pos][j - 1] + mas[pos][j],
                          pre[pos][j] + dyn[((pos + 1) % 2)][j - 1]);
    }
    pos = ((pos + 1) % 2);
  }
  pos = ((pos + 1) % 2);
  long long ans = -1000000000000000LL;
  if ((n - 1) % 2 == 1)
    for (int j = 0; j < m - 1; ++j) ans = max(ans, dyn[pos][j]);
  else
    for (int j = 1; j < m; ++j) ans = max(ans, dyn[pos][j]);
  cout << ans;
  return 0;
}
