#include <bits/stdc++.h>
using namespace std;
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()) {
  v.assign(a, vector<T>(b, t));
}
template <class F, class T>
void convert(const F &f, T &t) {
  stringstream ss;
  ss << f;
  ss >> t;
}
struct edge {
  int to, cap, cost, rev;
};
const int MAX_V = 6100;
int V;
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V], preve[MAX_V];
int top[MAX_V];
int s, t, l, r;
void add_edge(int from, int to, int cap, int cost) {
  edge e1 = {to, cap, cost, (int)G[to].size()},
       e2 = {from, 0, -cost, (int)G[from].size()};
  G[from].push_back(e1);
  G[to].push_back(e2);
}
int min_cost_flow(int s, int t, int f) {
  int res = 0;
  fill(h, h + V, 0);
  for (int(i) = (0); (i) < ((V)); ++(i)) {
    int v = top[i];
    for (int(j) = (0); (j) < ((G[v].size())); ++(j)) {
      edge &e = G[v][j];
      if (e.cap == 0) continue;
      int u = e.to;
      h[u] = min(h[u], h[v] + e.cost);
    }
  }
  while (f > 0) {
    priority_queue<pair<int, int>, vector<pair<int, int> >,
                   greater<pair<int, int> > >
        que;
    fill(dist, dist + V, 0x3f3f3f3f);
    dist[s] = 0;
    que.push(pair<int, int>(0, s));
    while (!que.empty()) {
      pair<int, int> p = que.top();
      que.pop();
      int v = p.second;
      if (dist[v] < p.first) continue;
      for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
          dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
          prevv[e.to] = v;
          preve[e.to] = i;
          que.push(pair<int, int>(dist[e.to], e.to));
        }
      }
    }
    if (dist[t] == 0x3f3f3f3f) return -1;
    for (int v = 0; v < V; v++) h[v] += dist[v];
    int d = f;
    for (int v = t; v != s; v = prevv[v]) {
      d = min(d, G[prevv[v]][preve[v]].cap);
    }
    f -= d;
    res += d * h[t];
    for (int v = t; v != s; v = prevv[v]) {
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}
void mainmain() {
  int H, W;
  cin >> H >> W;
  vector<vector<int> > vv;
  int off = H * W;
  V = H * W + off + 2;
  initvv(vv, H, W);
  int source = H * W + off;
  int sink = H * W + off + 1;
  if (H == W && H == 1) {
    int t;
    cin >> t;
    cout << t << endl;
    return;
  }
  for (int(i) = (0); (i) < ((H)); ++(i)) {
    for (int(j) = (0); (j) < ((W)); ++(j)) {
      cin >> vv[i][j];
    }
  }
  int ans = vv[0][0] + vv[H - 1][W - 1];
  vv[0][0] = 0;
  vv[H - 1][W - 1] = 0;
  for (int(i) = (0); (i) < ((H)); ++(i)) {
    for (int(j) = (0); (j) < ((W)); ++(j)) {
      int s = i * W + j;
      if (i || j) {
        add_edge(i * W + j, i * W + j + off, 1, 0);
        s += off;
      }
      if (i + 1 < H) {
        add_edge(s, i * W + W + j, 1, -vv[i + 1][j]),
            add_edge(s, i * W + W + j, 1, 0);
      }
      if (j + 1 < W) {
        add_edge(s, i * W + j + 1, 1, -vv[i][j + 1]),
            add_edge(s, i * W + j + 1, 1, 0);
      }
    }
  }
  add_edge(source, 0, 1, -vv[0][0]);
  add_edge(source, 0, 1, 0);
  add_edge(H * W - 1, sink, 2, 0);
  cout << -min_cost_flow(source, sink, 2) + ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  mainmain();
}
