#include <bits/stdc++.h>
using namespace std;
int movement[5][3][3];
int dp[1002][1002][5];
bool vis[1002][1002][5];
int n, m, maps[1002][1002];
int solve(int, int, int);
int main(void) {
  movement[0][0][0] = -1;
  movement[0][0][1] = 0;
  movement[0][1][0] = 0;
  movement[0][1][1] = -1;
  movement[1][0][0] = 1;
  movement[1][0][1] = 0;
  movement[1][1][0] = 0;
  movement[1][1][1] = -1;
  movement[2][0][0] = 1;
  movement[2][0][1] = 0;
  movement[2][1][0] = 0;
  movement[2][1][1] = 1;
  movement[3][0][0] = -1;
  movement[3][0][1] = 0;
  movement[3][1][0] = 0;
  movement[3][1][1] = 1;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &maps[i][j]);
  int ans = 0;
  for (int i = 1; i < n - 1; i++)
    for (int j = 1; j < m - 1; j++) {
      int buff = 0;
      buff = max(buff, solve(i - 1, j, 0) + solve(i + 1, j, 2) +
                           solve(i, j - 1, 3) + solve(i, j + 1, 1));
      buff = max(buff, solve(i - 1, j, 1) + solve(i + 1, j, 3) +
                           solve(i, j - 1, 0) + solve(i, j + 1, 2));
      ans = max(ans, buff);
    }
  printf("%d\n", ans);
  return 0;
}
int solve(int y, int x, int dir) {
  if (y < 0 || y >= n) return 0;
  if (x < 0 || x >= m) return 0;
  if (vis[y][x][dir]) return dp[y][x][dir];
  vis[y][x][dir] = true;
  int ans = 0;
  for (int i = 0; i < 2; i++) {
    ans =
        max(ans, solve(y + movement[dir][i][1], x + movement[dir][i][0], dir));
  }
  return dp[y][x][dir] = ans + maps[y][x];
}
