import java.io.BufferedReader import java.io.InputStream import java.io.InputStreamReader import java.io.PrintWriter import java.util.* fun PrintWriter.solve(sc: FastScanner) { val n = sc.nextInt() val t = Array(n) { sc.nextInt() } val lst = mutableListOf() val a = mutableListOf(0, 2, 4, 5, 7, 9, 11) for (d in 0 until 12) { var ok = true for (i in 0 until n) { var ok2 = false for (j in 0 until 7) { if (t[i] % 12 == (d + a[j]) % 12) { ok2 = true break } } if (!ok2) { ok = false break } } if (ok) { lst.add(d) } } println(if (lst.count() == 1) lst[0] else -1) } fun main() { val writer = PrintWriter(System.out, false) writer.solve(FastScanner(System.`in`)) writer.flush() } class FastScanner(s: InputStream) { private var st = StringTokenizer("") private val br = BufferedReader(InputStreamReader(s)) fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine() fun nextDouble() = next().toDouble() fun ready() = br.ready() }