import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] t = new int[n]; for (int i = 0; i < n; i++) { t[i] = sc.nextInt(); } sc.close(); int[] d = {0, 2, 4, 5, 7, 9, 11}; boolean[] match = new boolean[12]; Arrays.fill(match, true); for (int i = 0; i < 12; i++) { for (int j = 0; j < n; j++) { boolean flg = false; for (int j2 = 0; j2 < d.length; j2++) { if (t[j] == (i + d[j2]) % 12) { flg = true; break; } } if (!flg) { match[i] = false; break; } } } int ans = -1; for (int i = 0; i < 12; i++) { if (match[i]) { if (ans == -1) { ans = i; } else { System.out.println(-1); return; } } } System.out.println(ans); } }