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
num = int(raw_input())
if(num%2==0):
    i = num+1
else:
    i = num

ans = 0

while(ans!=2):
    p = i
    nu = 0
    ans= 0
    while(p>0):
        nu = (nu*10) + (p%10)
        p = p/10
    if(nu == i):
        ans+=1
    if(ans==1):
        flag = 0
        for j in range(2,(i/2)+1):
            if(i%j == 0):
                flag = 1
                break
        if(flag!=1):
            ans+=1
            
    i+=2
print nu