An integer is said to be a palindrome if it is equal to its
reverse.  For example, 79197 and 324423 are palindromes. In this task
you will be given an integer N, 1 ≤ N ≤ 1000000.  You must find
the smallest integer M ≥ N such that M is a prime number and M is a
palindrome.  
For example, if N is 31 then the answer is 101.

Input
A single integer N, (1 ≤ N ≤ 1000000), on a single line.

Output
Your output must consist of a single integer, the smallest prime
palindrome greater than or equal to N.

Example

Input:
31
Output:
101
import math

def isprime(n):
	if n==2:
		return True
	if n%2==0:
		return False
	s=math.sqrt(n)
	for i in xrange(3,int(s+1)):
		if n%i==0:
			return False
	return True

def nextpalin(n):
	ndig = len(str(n))

	a = n/(10**((ndig+1)/2))
	c = n%(10**(ndig/2))

	ar = int(str(a)[::-1])

	if c>=ar:
		if ndig%2==0:
			a+=1
			ar = int(str(a)[::-1])
			return a*(10**(ndig/2))+ar
		else:
			b = n%(10**((ndig+1)/2))/(10**(ndig/2))
			if b==9:
				b=0
				a+=1
				ar = int(str(a)[::-1])
			else:
				b+=1
			return a*(10**((ndig+1)/2))+b*(10**(ndig/2))+ar
	else:
		if ndig%2==0:
			return a*(10**(ndig/2))+ar
		else:
			b = n%(10**((ndig+1)/2))/(10**(ndig/2))
			return a*(10**((ndig+1)/2))+b*(10**(ndig/2))+ar

n=int(raw_input())

if n==int(str(n)[::-1]) and isprime(n):
	pass
else:
	while True:
		n=nextpalin(n)
		if isprime(n)==True:
			break

print n