#include <bits/stdc++.h>
using namespace std;
const long long M = 205;
long long read() {
  long long x = 0, y = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') y = (ch == '-') ? -1 : 1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * y;
}
long long n, a[M][M];
long long tot = 1, first[M * M];
struct Edge {
  long long nxt, to, w;
} e[M * M * 4];
void add(long long x, long long y) {
  e[++tot] = (Edge){first[x], y, 0}, first[x] = tot;
  e[++tot] = (Edge){first[y], x, 0}, first[y] = tot;
}
bool iS[M * M], iT[M * M], vis[M * M];
bool push(long long u, long long flow) {
  if ((iS[u] && flow == -1) || (iT[u] && flow == 1)) return 1;
  vis[u] = 1;
  for (long long i = first[u]; i; i = e[i].nxt) {
    long long v = e[i].to, w = e[i].w;
    if (vis[v] || (flow == 1 && w == 1) || (flow == -1 && w != -1)) continue;
    if (push(v, flow)) return e[i].w++, e[i ^ 1].w--, 1;
  }
  return 0;
}
vector<pair<long long, long long> > vec;
void solve() {
  n = read();
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= n; j++) a[i][j] = read();
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= n; j++)
      if (a[i][j] >= 0) {
        if (i < n && a[i + 1][j] >= 0)
          add(((i - 1) * n + j), ((i + 1 - 1) * n + j));
        if (j < n && a[i][j + 1] >= 0)
          add(((i - 1) * n + j), ((i - 1) * n + j + 1));
        if (a[i][j] > 0)
          iT[((i - 1) * n + j)] = 1, vec.push_back(
                                         make_pair(a[i][j], ((i - 1) * n + j)));
      }
  sort(vec.begin(), vec.end());
  long long Ans = 0, flow = 0;
  for (long long i = 0; i < vec.size() - 1; i++) {
    long long u = vec[i].second;
    memset(vis, 0, sizeof vis);
    while (push(u, -1)) flow--, memset(vis, 0, sizeof vis);
    iT[u] = 0, iS[u] = 1;
    for (long long j = 0; j <= i; j++)
      while (push(vec[j].second, 1)) flow++, memset(vis, 0, sizeof vis);
    Ans += (vec[i + 1].first - vec[i].first) * flow;
  }
  printf("%lld\n", Ans);
}
signed main() { solve(); }
