#include using namespace std; int main() { int n; cin >> n; vector t(n); for (int i = 0; i < n; i++) { cin >> t.at(i); } if (n <= 2 || n >= 8) { cout << -1 << endl; } else { int answer = -1; bool first = false; bool second = false; for (int i = 0; i < 12; i++) { for (int j = 0; j < n; j++) { int x = (t.at(j) - i + 12) % 12; if (x != 0 && x != 2 && x != 4 && x != 5 && x != 7 && x != 9 && x != 11) { break; } else if (j == n - 1) { if (first) { second = true; } answer = i; first = true; } } if (second) { cout << -1 << endl; break; } else if (i == 11) { cout << answer << endl; } } } }