import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); HashSet correct = new HashSet<>(); correct.add(0); correct.add(2); correct.add(4); correct.add(5); correct.add(7); correct.add(9); correct.add(11); boolean[] durs = new boolean[12]; Arrays.fill(durs, true); for (int i = 0; i < n; i++) { int x = sc.nextInt(); for (int j = 0; j < 12; j++) { if (!durs[j]) { continue; } if (!correct.contains((x - j + 12) % 12)) { durs[j] = false; } } } int ans = -1; for (int i = 0; i < 12; i++) { if (durs[i]) { if (ans == -1) { ans = i; } else { ans = -1; break; } } } System.out.println(ans); } }