#include using namespace std; int main(void) { cin.tie(0); ios::sync_with_stdio(false); vector add = { 0,2,4,5,7,9,11 }; vector v; int n, t; int cnt = 0; int res = -1; cin >> n; for (int i = 0; i < n; i++) { cin >> t; v.push_back(t); } for (int i = 0;i<12;i++) { bool check[12]; memset(check, false, sizeof(check)); for (int j = 0; j < add.size(); j++) { int val = add[j] + i; val %= 12; check[val] = true; } bool ok = true; for (int j = 0; j < n; j++) { if (check[v[j]] == false) { ok = false; break; } } if (ok) { cnt++; res = i; } } if (cnt > 1) res = -1; cout << res << '\n'; return 0; }