import math def prime(max): max2 = (max-3)//2 sieve = [True]*(max2+1) for i in range(int((math.sqrt(max)-3)/2)+1): if not sieve[i]: continue k = i+i+3 j = k*(i+1)+i while j <= max2: sieve[j] = False j += k sieve = [2]+[i+i+3 for i in range(max2+1) if sieve[i]] return sieve input() a=set(input().split()) max=5000000 start=1 rest=a ans=-1 for i in prime(max): l=set(str(i)) if len(l-a): if len(rest)==0 and ans