#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; vector p = {0,2,4,5,7,9,11}; int main(){ int n; cin >> n; vector cnt(20,0); rep(i,n){ int a; cin >> a; cnt[a] = 1; } int d = -1; rep(i,12){ bool res = true; rep(j,12){ if(cnt[j]==1){ bool ok = false; rep(k,p.size()){ if((i+p[k])%12==j) ok = true; } if(!ok) res = false; } } if(res&&d!=-1){d = INF;break;} if(res) d = i; } if(d==INF) cout << -1 << endl; else cout << d << endl; return 0; }