# Input M = int(input()) A = list(map(int, input().split())) bit = sum(2 ** x for x in A) # Eratosthenes' sieve LIMIT = 5000000 prime = [ True ] * (LIMIT + 1) prime[0], prime[1] = False, False for i in range(2, LIMIT + 1): if prime[i]: for j in range(i * 2, LIMIT + 1, i): prime[j] = False plist = list(filter(lambda x: prime[x], range(2, LIMIT + 1))) # Calculation K = len(plist) recent = [ -1 ] * 10 answer = -1 for i in range(K): x = plist[i] while x > 0: recent[x % 10] = i x //= 10 recmin, recmax = i + 1, -1 for j in range(10): if ((bit >> j) & 1) == 1: recmin = min(recmin, recent[j]) else: recmax = max(recmax, recent[j]) if recmax < recmin: truel = (plist[recmax] + 1 if recmax != -1 else 1) truer = (plist[i + 1] - 1 if i != K - 1 else LIMIT) answer = max(answer, truer - truel) print(answer)