#include //全てのヘッダファイルをインクルード //ループ #define rep(i, n) for(int i = 0; i < (n); i++) //普通のループ #define repr(i, n) for(int i = n; i >= 0; i--) //逆ループ //型名省略 typedef long long ll; //値 static const ll MX = 100005; static const ll MX_ll = 1e18; using namespace std; //#include "./lib/generic/search.h" int main(){ int n; cin >> n; int t[n], chk[7], ans=0, cnt=0, cnt2=0; rep(i, n){ cin >> t[i]; chk[i] = 0; } rep(i, n){ chk[0] = t[i]%12; chk[1] = (t[i]+2)%12; chk[2] = (t[i]+4)%12; chk[3] = (t[i]+5)%12; chk[4] = (t[i]+7)%12; chk[5] = (t[i]+9)%12; chk[6] = (t[i]+11)%12; rep(j, n){ rep(k, 7){ if(t[j]==chk[k]) cnt++; } } if(cnt==n && cnt2==0){ cnt2 = 1; ans = t[i]; cnt = 0; } else if(cnt==n && cnt2==1){ cnt2 = 2; break; } cnt = 0; } if(cnt2==1) cout << ans << endl; else cout << "-1" << endl; return 0; }