#include using namespace std; vector d = {0, 2, 4, 5, 7, 9, 11}; int main(){ int N; cin >> N; vector T(N); for (int i = 0; i < N; i++){ cin >> T[i]; } set ans; for (int i = 0; i < 12; i++){ set st; for (int j = 0; j < 7; j++){ st.insert((i + d[j]) % 12); } bool ok = true; for (int j = 0; j < N; j++){ if (!st.count(T[j])){ ok = false; } } if (ok){ ans.insert(i); } } if (ans.size() != 1){ cout << -1 << endl; } else { cout << *ans.begin() << endl; } }