#include <bits/stdc++.h>
using namespace std;
long long INF = 100000000000LL;
struct edge {
  long long to, cap, cost, rev;
};
int V;
vector<edge> G[50000];
long long h[50000];
long long dist[50000];
int prevv[50000], preve[50000];
void init_edge() {
  for (int i = 0; i < V; i++) G[i].clear();
}
void add_edge(int from, int to, int cap, long long cost) {
  G[from].push_back((edge){to, cap, cost, (int)G[to].size()});
  G[to].push_back((edge){from, 0, -cost, (int)G[from].size() - 1});
}
long long min_cost_flow(int s, int t, int f) {
  long long res = 0;
  fill(h, h + V, 0);
  while (f > 0) {
    priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                   greater<pair<long long, int> > >
        que;
    fill(dist, dist + V, INF);
    dist[s] = 0;
    que.push(pair<long long, int>(0, s));
    while (!que.empty()) {
      pair<long long, int> p = que.top();
      que.pop();
      int v = p.second;
      if (dist[v] < p.first) continue;
      for (int i = 0; i < (int)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<long long, int>(dist[e.to], e.to));
        }
      }
    }
    if (dist[t] == INF) {
      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, (int)G[prevv[v]][preve[v]].cap);
    }
    f -= d;
    res += (long long)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;
}
int H, W;
int t[200][200];
int main() {
  cin >> H >> W;
  int si = H * W * 2;
  int ti = si + 1;
  V = ti + 1;
  int N = H * W;
  long long mx = 1e6;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> t[i][j];
      add_edge(i * W + j, i * W + j + N, 1, mx);
      add_edge(i * W + j, i * W + j + N, 1, mx - t[i][j]);
      if (i + 1 < H) {
        int id = (i + 1) * W + j;
        add_edge(i * W + j + N, id, 2, 0);
      }
      if (j + 1 < W) {
        int id = i * W + (j + 1);
        add_edge(i * W + j + N, id, 2, 0);
      }
    }
  }
  add_edge(si, 0, 2, 0);
  add_edge((H - 1) * W + (W - 1) + N, ti, 2, 0);
  long long ans = min_cost_flow(si, ti, 2);
  ans -= mx * (H + W - 1) * 2;
  cout << -ans << endl;
  return 0;
}
