#include #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; template bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; set st; rep(i, n){ int t; cin >> t; st.insert(t); } int cnt = 0; int x = -1; rep(i, 12){ int u = 0; if(st.count((i) % 12) == 1) u++; if(st.count((i+2) % 12) == 1) u++; if(st.count((i+4) % 12) == 1) u++; if(st.count((i+5) % 12) == 1) u++; if(st.count((i+7) % 12) == 1) u++; if(st.count((i+9) % 12) == 1) u++; if(st.count((i+11) % 12) == 1) u++; if(u == n) { cnt++; x = i; } } if(cnt == 1){ cout << x << endl; }else{ cout << -1 << endl; } }