#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { int32_t n; cin >> n; vector ts(n); for (auto &&t : ts) { cin >> t; } vector ans; vector dds = {0, 2, 4, 5, 7, 9, 11}; for (auto d = 0; d < 12; ++d) { bool found = true; for (auto t : ts) { bool matches = false; for (auto dd : dds) { if ((d + dd) % 12 == t) { matches = true; break; } } if (!matches) { found = false; break; } } if (found) ans.push_back(d); } cout << (ans.size() == 1 ? ans[0] : -1) << endl; return 0; }