#include #define rep(X,N) for(ll X = 0LL; X < (N); X++) #define ALL(V) (V).begin(),(V).end() using namespace std; typedef long long ll; const double PI = 3.1415926535897932384626; const ll MODN = 1000000007; const ll MODN2 = 998244353; const double EPS = 1e-10; int main(){ int n; cin >> n; vector t(n); rep(i, n) cin >> t[i]; int ans = -1; vector diff = {0, 2, 4, 5, 7, 9, 11}; rep(i, 12){ bool tmp = true; rep(j, n){ bool tmp2 = false; rep(k, 7){ if(t[j] == (i + diff[k]) % 12){ tmp2 = true; break; } } if(!tmp2){ tmp = false; break; } } if(tmp){ if(ans == -1){ ans = i; }else{ ans = -1; break; } } } cout << ans << endl; return 0; }