#include #define PI 3.14159265359 using namespace std; const int64_t mod = 1e9 + 7; int main() { int N; cin >> N; vector v(N); for (int i = 0; i < N; i++) { cin >> v.at(i); //cout << v.at(i) << endl; } int D; bool b; vector v2(12); for (int i = 0; i < 12; i++) { b = true; int cnt = 0; for (int j = 0; j < N; j++) { int T = v.at(j); //cout << j << endl; if ((i % 12 != T) && ((i + 2) % 12 != T) && ((i + 4) % 12 != T) && ((i + 5) % 12 != T) && ((i + 7) % 12 != T) && ((i + 9) % 12 != T) && ((i + 11) % 12 != T)) { b = false; break; } if (b) cnt++; } if (b) v2.at(i) = cnt; } //cout << count(v2.begin(), v2.end(), N) << endl; if (count(v2.begin(), v2.end(), N) == 1) { //cout << 1 << endl; for (int i = 0; i < 12; i++) { if (v2.at(i) == N) { cout << i << endl; return 0; } } } else { cout << -1 << endl; } }