#include #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; int main() { int N; cin >> N; vector T(N); rep(i, N) { cin >> T[i]; } vector sum = {0, 2, 4, 5, 7, 9, 11}; int mod = 12; vector ans; for (int d = 0; d < 12; d++) { vector x(7); rep(i, x.size()) { x[i] = (d + sum[i]) % mod; } bool total_exists = true; rep(i, N) { int t = T[i]; bool exist = false; rep(j, x.size()) { // T[i]がx[j]と同じものがあるかどうか if (t == x[j]) { exist = true; break; } } if (!exist) { total_exists = false; break; } } if (total_exists) { ans.push_back(d); } } if (ans.size() == 1) { cout << ans.back() << endl; } else { cout << -1 << endl; } }