#include <bits/stdc++.h>
using namespace std;
long long a[1000][1000];
int main() {
  ios_base::sync_with_stdio(0);
  long long n, i, j, x, y, s1 = 0, s2 = 0, s = 0, k;
  cin >> n;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) {
      cin >> a[i][j];
      if (a[i][j] == 0) x = i, y = j;
    }
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  for (i = 1; i <= n; i++) {
    if (i != x) {
      for (j = 1; j <= n; j++) s1 += a[i][j];
      break;
    }
  }
  for (i = 1; i <= n; i++) {
    if (i == x)
      for (j = 1; j <= n; j++) s2 += a[i][j];
  }
  if (s2 >= s1) {
    cout << -1 << endl;
    return 0;
  }
  a[x][y] = s1 - s2;
  for (i = 1; i <= n; i++) {
    s = 0;
    for (j = 1; j <= n; j++) s += a[i][j];
    if (s != s1) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (i = 1; i <= n; i++) {
    s = 0;
    for (j = 1; j <= n; j++) s += a[j][i];
    if (s != s1) {
      cout << -1 << endl;
      return 0;
    }
  }
  s = 0;
  for (i = 1; i <= n; i++) {
    s += a[i][i];
  }
  if (s != s1) {
    cout << -1 << endl;
    return 0;
  }
  s = 0;
  k = n;
  for (i = 1; i <= n; i++) {
    s += a[i][k];
    k--;
  }
  if (s != s1) {
    cout << -1 << endl;
    return 0;
  }
  cout << a[x][y] << endl;
  return 0;
}
