#include #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair P; #define yn {puts("YES");}else{puts("NO");} #define MAX_N 200005 int main() { int n; cin >> n; int t[n]; rep(i,n)cin >> t[i]; int f[12]; rep(i,12)f[i] = 1; int a[7] = {0,2,4,5,7,9,11}; rep(i,12){ rep(j,n){ int flag = 0; rep(k,7){ if(t[j] == (i + a[k]) % 12){ flag = 1; break; } } if(flag == 0){ f[i] = 0; break; } } } int arg = -1; rep(i,12){ if(f[i]){ if(arg != -1){ cout << -1 << endl; return 0; } arg = i; } } cout << arg << endl; return 0; }