#include using namespace std; struct iofast_t { iofast_t() { ios::sync_with_stdio(false); cin.tie(nullptr); } } iofast; struct uns_t {} uns; template auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return std::vector(arg, init); else return std::vector(arg, vec(init, args...)); } template auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } template > T &chmin(T &l, T r, Compare &&f = less()) { return l = min(l, r, f); } template > T &chmax(T &l, T r, Compare &&f = less()) { return l = max(l, r, f); } int main() { constexpr int mod = 12; constexpr int ofs[] = { 0, 2, 4, 5, 7, 9, 11, }; int n; cin >> n; int t[mod] = {}; for (int i = 0; i < n; ++i) { int v; cin >> v; ++t[v]; } auto ans = vec(uns, 0); for (int i = 0; i < mod; ++i) { int sum = 0; for (auto v : ofs) { sum += t[(i + v) % mod]; } if (sum == n) { ans.push_back(i); } } if (size(ans) == 1) { cout << ans[0] << endl; } else { cout << -1 << endl; } }