#include using namespace std; using ll = long long; constexpr char newl = '\n'; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector t(n); for (int i = 0; i < n; i++) { cin >> t[i]; } vector ans; for (int i = 0; i < 12; i++) { set s; for (int j : {0, 2, 4, 5, 7, 9, 11}) { s.insert((i + j) % 12); } bool f = true; for (int j = 0; j < n; j++) { if (s.find(t[j]) == s.end()) { f = false; break; } } if (!f) continue; ans.push_back(i); } cout << (ans.size() != 1 ? -1 : ans[0]) << newl; return 0; }