#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef long double ld; typedef pair P; int a[] = {0, 2, 4, 5, 7, 9, 11}; int main() { int n; cin >> n; vector t(n); rep(i,n) cin >> t[i]; vector res; for (int d = 0; d < 12; d++) { set st; for (int i = 0; i < 7; i++) { st.insert((d + a[i]) % 12); } bool ok = true; for (int i = 0; i < n; i++) { if (!st.count(t[i])) ok = false; } if (ok) res.emplace_back(d); } if (res.size() != 1) cout << -1 << endl; else cout << res.front() << endl; return 0; }