#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { int n; cin >> n; vector a(n); rep(i, n) cin >> a[i]; vector ans(0); rep(x, 12) { set s; s.insert(x), s.insert((x + 2) % 12), s.insert((x + 4) % 12), s.insert((x + 5) % 12), s.insert((x + 7) % 12), s.insert((x + 9) % 12), s.insert((x + 11) % 12); bool ok = true; rep(i, n) { if (!s.contains(a[i])) ok = false; } if (ok) ans.push_back(x); } if (ans.size() == 1) { cout << ans[0] << endl; } else { cout << -1 << endl; } return 0; }