#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const long long MOD = 1000000000 + 7;
constexpr long long INF = 1LL << 60;
const double PI = acos(-1);
struct Tll {
  LL first, second, third;
};
struct Fll {
  LL first, second, third, fourth;
};
void YN(bool f) {
  if (f)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
void yn(bool f) {
  if (f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
struct Edge {
  LL to, cost;
};
struct edge {
  LL from, to, cost;
};
vector<vector<Edge>> g;
vector<edge> ed;
vector<pair<LL, LL>> pv;
set<LL> st;
map<pair<LL, LL>, LL> ma;
int di[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
string str, ss;
bool f;
LL n, m, s, t, h, w, k, q, p, ans, sum, cnt, a[300][300], b[210000],
    dp[5000][5000];
vector<LL> vec;
vector<LL> tsort(vector<vector<Edge>> g) {
  int n = g.size();
  enum { YET, VISITED, DONE };
  vector<LL> res, flg(g.size(), YET);
  static const function<bool(int)> dfs = [&](int v) {
    flg[v] = VISITED;
    for (auto &e : g[v]) {
      int w = e.to;
      if (flg[w] != DONE && (flg[w] == VISITED || !dfs(w))) return false;
    }
    flg[v] = DONE;
    res.push_back(v);
    return true;
  };
  for (int i = 0; i < n; ++i)
    if (flg[i] == YET && !dfs(i)) return {};
  reverse(res.begin(), res.end());
  return res;
}
void dijkstra() {
  LL s = 0;
  struct info {
    LL p1, p2, cost;
  };
  auto comp = [](info x, info y) { return (x.cost > y.cost); };
  priority_queue<info, vector<info>, decltype(comp)> pq(comp);
  pq.push(info{0, 0, 0});
  while (!pq.empty()) {
    info num = pq.top();
    pq.pop();
    LL v = num.p1, u = num.p2, cost = num.cost;
    if (dp[u][v] > cost) continue;
    for (LL i = 0; i < g[v].size(); i++) {
      LL nex = g[v][i].to, cos = g[v][i].cost;
      if (vec[nex] > vec[u]) {
        if (dp[nex][u] < dp[u][v] + cos) {
          dp[nex][u] = dp[u][v] + cos;
          pq.push(info{u, nex, dp[nex][u]});
        }
      } else if (vec[u] > vec[nex]) {
        if (dp[u][nex] < dp[u][v] + cos) {
          dp[u][nex] = dp[u][v] + cos;
          pq.push(info{nex, u, dp[u][nex]});
        }
      } else {
        if (dp[u][nex] < dp[u][v]) {
          dp[u][nex] = dp[u][v];
          pq.push(info{u, nex, dp[u][nex]});
        }
      }
    }
  }
}
int main() {
  cin >> h >> w;
  g.resize(h * w);
  for (LL i = 0; i < h; i++) {
    for (LL j = 0; j < w; j++) {
      cin >> a[i][j];
      LL cur = j + i * w;
      if (i) {
        g[j + (i - 1) * w].push_back(Edge{cur, a[i][j]});
      }
      if (j) {
        g[j - 1 + i * w].push_back(Edge{cur, a[i][j]});
      }
    }
  }
  vec = tsort(g);
  dijkstra();
  cout << dp[h * w - 1][h * w - 1] + a[0][0] << endl;
  return 0;
}
