#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x;
  long long out = 0;
  cin >> n;
  if (n == 1) {
    cin >> x;
    cout << 1;
    return 0;
  }
  set<long long> hor, ver;
  long long arr[n][n];
  long long ans, ans2;
  for (int i = 0; i < n; i++) {
    int flag = 0;
    long long sm = 0;
    for (int j = 0; j < n; j++) {
      cin >> arr[i][j];
      sm += arr[i][j];
      if (arr[i][j] == 0) flag = 1;
    }
    if (flag == 0) {
      ans = sm;
      hor.insert(sm);
    }
  }
  for (int j = 0; j < n; j++) {
    long long sm = 0;
    int flag = 0;
    for (int i = 0; i < n; i++) {
      sm += arr[i][j];
      if (arr[i][j] == 0) {
        flag = 1;
      }
    }
    if (flag == 0) {
      ans2 = sm;
      ver.insert(sm);
    } else {
      for (int i = 0; i < n; i++) {
        if (arr[i][j] == 0) {
          if ((ans - sm) > 0) {
            arr[i][j] = ans - sm;
            out = arr[i][j];
          } else {
            cout << -1;
            return 0;
          }
        }
      }
    }
  }
  if (ans != ans2 || ver.size() != 1 || hor.size() != 1) {
    cout << -1;
    return 0;
  }
  set<long long> fin;
  long long sm1 = 0, sm2 = 0;
  for (int i = 0; i < n; i++) {
    long long sm = 0;
    for (int j = 0; j < n; j++) {
      sm += arr[i][j];
      if (i == j) {
        sm1 += arr[i][j];
      }
      if (i + j == n - 1) {
        sm2 += arr[i][j];
      }
    }
    fin.insert(sm);
  }
  if (fin.size() != 1) {
    cout << -1;
    return 0;
  }
  if (sm1 != sm2 || sm1 != ans) {
    cout << -1;
    return 0;
  }
  cout << out;
  return 0;
}
