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
a=input()
def is_prime(n):
    t=True
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            t=False
            break
    return t        
m=False 
i=a           
while  not m:
   
    #i=a+1
    #print i
    j=str(i)
    if j==j[::-1] and is_prime(i)==True:
        m=True
        print i
    else:
         i=i+1