import java.io.InputStreamReader; import java.io.IOException; import java.io.BufferedReader; public class Main{ public static void main(String args[]) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = br.readLine(); if(line.charAt(line.length()-1) == ' ') System.exit(1); int n = Integer.parseInt(line); if(!(1 <= n && n <= 12)) System.exit(1); line = br.readLine(); if(line.charAt(line.length()-1) == ' ') System.exit(1); String[] tmp = line.split(" "); if(tmp.length != n) System.exit(1); int[] arr = new int[n]; for(int i = 0; i < n; i++) arr[i] = Integer.parseInt(tmp[i]); for(int i = 1; i < n; i++){ if(!(arr[i-1] < arr[i])) System.exit(1); } boolean[] x = new boolean[12]; for(int i = 0; i < n; i++){ if(!(0 <= arr[i] && arr[i] < 12)) System.exit(1); x[arr[i]] = true; } int[] add = {0, 2, 4, 5, 7, 9, 11}; int ans = -1; for(int i = 0; i < 12; i++){ int count = 0; for(int j : add){ if(x[(i+j)%12]) count++; } if(count != n) continue; if(ans != -1){ ans = -1; break; } ans = i; } System.out.println(ans); } }