#include <bits/stdc++.h>
int diru[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dirv[] = {-1, 0, 1, -1, 1, -1, 0, 1};
using namespace std;
template <class T>
T sq(T n) {
  return n * n;
}
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
template <class T>
bool inside(T a, T b, T c) {
  return a <= b && b <= c;
}
template <class T>
void setmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
void setmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
T power(T N, T P) {
  return (P == 0) ? 1 : N * power(N, P - 1);
}
bool isV[1510][1510][2];
long long int dp[1510][1510][2];
long long int sum[1510][1510];
int r, c;
long long int I = (1 << 29);
long long int cal(int i, int j, int f) {
  if (i == r) return 0;
  if (j < 0 || j >= c) return -I;
  if (isV[i][j][f]) return dp[i][j][f];
  long long int ret;
  if (f == 0) {
    ret = max(sum[i][j] + cal(i + 1, j - 1, 1), cal(i, j + 1, 0));
  } else {
    ret = max(sum[i][j] + cal(i + 1, j + 1, 0), cal(i, j - 1, 1));
  }
  isV[i][j][f] = 1;
  return dp[i][j][f] = ret;
}
int main() {
  int n, T, t = 1, m, i, j, k;
  I *= I;
  scanf("%d", &r);
  scanf("%d", &c);
  {
    for (i = 0; i < r; i++) {
      for (j = 0; j < c; j++) {
        scanf("%d", &m);
        if (j)
          sum[i][j] = sum[i][j - 1] + (long long int)m;
        else
          sum[i][j] = (long long int)m;
      }
    }
    cout << cal(0, 0, 0) << endl;
  }
  return 0;
}
