num = input()
combs = {int(num), int(num[:3]), int(num[1:])} | {int(d) for d in num} | {int(num[i:i+2]) for i in range(len(num)-1)}
num = int(num)
prime = [False, False] + [True] * (num - 1)
for p in range(2, int(num**0.5) + 1):
if prime[p]:
for multiple in range(p*p, num + 1, p):
prime[multiple] = False
print(max((i for i in combs if i <= num and prime[i]), default=0))