#include #include #include #include #include #include #include #include using namespace std; int main() { int n, ans=0, onlyone = 0; bool no1, no2; cin >> n; vector v(n), d = {0, 2, 4, 5, 7, 9, 11}; for (int i = 0; i < n; i++) cin >> v[i]; for (int k = 0; k < 12; k++){ no2 = true; for (int i = 0; i < n; i++){ no1 = true; for (int j = 0; j < 7; j++){ if ((v[i] - k + 12)%12 == d[j]){ no1 = false; break; } } if (no1) break; if (i == n-1) no2 = false; } if (!no2){ onlyone++; ans = k; if (onlyone >= 2){ cout << -1 << endl; return 0; } } } if (onlyone) cout << ans << endl; else cout << -1 << endl; }