#include <bits/stdc++.h>
int take() {
  int n;
  scanf("%d", &n);
  return n;
}
double ttake() {
  double n;
  scanf("%lf", &n);
  return n;
}
long long takes() {
  long long n;
  scanf("%lld", &n);
  return n;
}
int cas;
using namespace std;
bool approximatelyEqual(float a, float b, float epsilon) {
  return fabs(a - b) <= ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
bool essentiallyEqual(float a, float b, float epsilon) {
  return fabs(a - b) <= ((fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
bool definitelyGreaterThan(float a, float b, float epsilon) {
  return (a - b) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
bool definitelyLessThan(float a, float b, float epsilon) {
  return (b - a) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
long long col[505], ro[505];
int main() {
  int n = take(), arr[n + 1][n + 1];
  if (n == 1) {
    printf("1");
    { return 0; };
  }
  int row = 1, cl = 1;
  set<long long> res1, res2;
  for (int i = 1; i <= n; i += 1) {
    long long sum = 0;
    for (int j = 1; j <= n; j += 1) {
      arr[i][j] = take();
      ro[i] += arr[i][j];
      col[j] += arr[i][j];
      if (!arr[i][j]) row = i, cl = j;
    }
  }
  for (int i = 1; i <= n; i += 1) {
    if (row != i) res1.insert(ro[i]);
    if (cl != i) res1.insert(col[i]);
  }
  long long dia = 0, g = 0;
  for (int i = 1; i <= n; i += 1) {
    dia += arr[i][i];
    if (row == i && cl == i) g = 1;
  }
  if (!g)
    res1.insert(dia);
  else
    res2.insert(dia);
  dia = 0;
  int k = 1;
  g = 0;
  for (int i = n; i >= 1; i--) {
    dia += arr[k][i];
    if (row == k && cl == i) g = 1;
    k++;
  }
  if (!g)
    res1.insert(dia);
  else
    res2.insert(dia);
  res2.insert(ro[row]);
  res2.insert(col[cl]);
  if (res1.size() > 1 || res2.size() > 1 || *res1.begin() <= *res2.begin()) {
    printf("-1");
    printf("\n");
    { return 0; };
  }
  long long d = abs(*res1.begin() - *res2.begin());
  printf("%lld\n", d);
  { return 0; };
}
