#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; int main() { int N; cin >> N; vector T(N); for (int i = 0; i < N; i++) cin >> T[i]; int cnt = 0, ans = -1; for (int D = 0; D < 12; D++) { bool flag = true; for (int i = 0; i < N; i++) { int t = T[i] % 12; if (t == D % 12) flag = true; else if (t == (D + 2) % 12) flag = true; else if (t == (D + 4) % 12) flag = true; else if (t == (D + 5) % 12) flag = true; else if (t == (D + 7) % 12) flag = true; else if (t == (D + 9) % 12) flag = true; else if (t == (D + 11) % 12) flag = true; else { flag = false; break; } } if (flag) ans = D, cnt++; } cout << (cnt == 1 ? ans: -1) << endl; return 0; }