#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define llint long long #define inf 1e18 #define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++) #define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) using namespace std; typedef pair P; llint n; llint t[15]; string s = "101011010101"; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 1; i <= n; i++) cin >> t[i]; llint ans = -1; for(int i = 0; i < 12; i++){ bool flag = true; for(int j = 1; j <= n; j++){ flag &= (s[(t[j]+12-i)%12] == '1'); } if(flag){ if(ans != -1){ cout << -1 << endl; return 0; } ans = i; } } cout << ans << endl; return 0; }