#include <bits/stdc++.h>
namespace std {
long long abs(long long x) { return x < 0 ? -x : x; }
}  // namespace std
using namespace std;
void dprintf(char* format, ...) {
  fprintf(stderr, "DEBUG: ");
  va_list argp;
  va_start(argp, format);
  vfprintf(stderr, format, argp);
  va_end(argp);
  fprintf(stderr, "\n");
}
struct Exception {
  const char* message;
  const int line;
  Exception(const char* m, int l) : message(m), line(l) {}
};
static char stringReader[2097152];
static inline bool ReadLine() {
  char* ptr = fgets(stringReader, sizeof(stringReader), stdin);
  if (ptr == 0) return false;
  int N = strlen(stringReader);
  if (stringReader[N - 1] == '\n') stringReader[N - 1] = 0;
  return true;
}
const long long ooLL = 0x3f3f3f3f3f3f3f3fLL;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
vector<vector<int> > table;
int n, m;
int main() {
  try {
    scanf("%d%d", &n, &m);
    table.assign(n, vector<int>(m));
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) {
        scanf("%d", &table[i][j]);
        if (j > 0) table[i][j] += table[i][j - 1];
      }
    static long long dp[1510][1510];
    memset(dp, 0xC0, sizeof(dp));
    for (int i = 0; i <= m + 1; ++i) dp[n][i] = 0;
    for (int i = n - 1; i >= 0; --i) {
      if (i % 2) {
        long long top = -oo;
        for (int j = m; j > 0; --j) {
          top = max(top, dp[i + 1][j + 1]);
          dp[i][j] = table[i][j - 1] + top;
        }
      } else {
        long long top = -oo;
        for (int j = 1; j <= m; ++j) {
          top = max(top, dp[i + 1][j - 1]);
          dp[i][j] = table[i][j - 1] + top;
        }
      }
    }
    long long sol = *max_element(dp[0], dp[0] + (m + 2));
    printf("%lld\n", sol);
    return 0;
  } catch (const Exception& exception) {
    fprintf(stderr, "******************************\n");
    fprintf(stderr, "ERROR.%d: %s\n", exception.line, exception.message);
    fprintf(stderr, "******************************\n");
    throw exception;
  }
}
