#include using namespace std; #include using namespace atcoder; using ll = long long; using vi = vector; using vvi = vector>; using pii = pair; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define repr(i, n) for (int i = (int)(n - 1); i >= 0; --i) ll gcd(ll x, ll y) { if (x > y) swap(x, y); return x == 0 ? y : gcd(y % x, x); } int main() { int n; cin >> n; vector a(n); rep(i, n) cin >> a[i]; for (int i = 1; i < n; i <<= 1) { for (int j = 0; j < n; j++) { if (i & j) { if (a[i ^ j] < 0 || a[j] < 0) { a[i ^ j] = -1; } else { a[i ^ j] += a[j]; } } } } ll r = 0; rep(i, n) { if (a[i] >= 0) { r = gcd(r, a[i] * a[i]); } } cout << (r == 0 ? -1 : r) << endl; return 0; }