#include using namespace std; int main() { int64_t n; cin >> n; vector t(n), ans; for (int64_t i = 0; i < n; i++) cin >> t[i]; int64_t d[7] = {0, 2, 4, 5, 7, 9, 11}; for (int64_t i = 0; i < 12; i++) { bool flag = true; for (int64_t j = 0; j < n; j++) { bool check = false; for (int64_t k = 0; k < 7; k++) if (t[j] % 12 == (i + d[k]) % 12) check = true; if (!check) { flag = false; break; } } if (flag) ans.push_back(i); } if (ans.size() == 1) cout << ans[0] << '\n'; else cout << "-1\n"; return 0; }