#include using namespace std; using ll = long long; using PII = pair; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() template void chmin(T &a, const T &b) { a = min(a, b); } template void chmax(T &a, const T &b) { a = max(a, b); } struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio; #ifdef DEBUG_ #include "../program_contest_library/memo/dump.hpp" #else #define dump(...) #endif const ll INF = 1LL<<60; // a.size() は2べき // upper: g(S) = \sum_{S \subseteq T} f(T) // lower: g(S) = \sum_{T \subseteq S} f(T) template vector fzt(vector a) { const int n = log2(a.size()); REP(i, n) REP(j, 1LL< vector fmt(vector a) { const int n = log2(a.size()); REP(i, n) REP(j, 1LL< convAND(vector a, vector b) { a = fzt(a); b = fzt(b); REP(i, a.size()) a[i] *= b[i]; return fmt(a); } // a.size(),b.size() は2べき // c_k = \sum_{k = i | j} a_ib_j vector convOR(vector a, vector b) { a = fzt(a); b = fzt(b); REP(i, a.size()) a[i] *= b[i]; return fmt(a); } int main(void) { ll n; cin >> n; vector a(n); REP(i, n) { cin >> a[i]; if(a[i]==-1) a[i] = 0; } if(n <= 20) { auto v = convAND(a, a); ll g = 0; REP(i, n) g = gcd(g, v[i]); cout << (g==0 ? -1 : g) << endl; } else { ll g = 0; REP(i, n) g = gcd(g, a[i]); cout << (g==0 ? -1 : g*g) << endl; } return 0; }