#include using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; template using vc = vector; template using vvc = vc>; using pi = pair; using vi = vc; using vvi = vvc; #define rep(i,a,b) for (int i = a; i < b; i++) #define irep(i,a,b) for (int i = a; i > b; i--) #define print(n) cout << n << endl #define rup(a,b) (a+b-1)/b int main(){ cout << fixed << setprecision(15); int N; cin>>N; int T[N]; rep(i,0,N) cin>>T[i]; int now = -1; bool p = false; int d[]={0,2,4,5,7,9,11}; int k[7]; rep(i,0,12){ rep(j,0,7){ k[j] = (i+d[j]) % 12; } bool qq = true; rep(j,0,N){ bool q = false; rep(a,0,7){ if(T[j]==k[a]){ q = true; break; } } if (q) continue; else { qq = false; break;} } if(qq){ if(!p){ now = i; p = true; continue; }else{ print(-1); return 0; } } } print(now); //system("pause"); return 0; }