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
from math import sqrt
import sys
def is_prime(t):
    i=2
    if t<2:
        return False
        
    while(i*i <= t):
        if t%i==0:
            return False
            break
        i+=1
    return True
    
        
       
'''def is_palindrome(t):
    flag=False
    string=str(t)
    length=len(string)
    count=0
    for i in range(0,length/2):
        if(string[i]==string[length-1-i]):
            count+=1
        else:
            break
    if count==length/2:
        return True
    else:
        return False
'''
def is_palindrome(n):
	s = str(n)
	return s==s[::-1]
	

def start():
    t= int (raw_input())
    while(True):
        if(is_palindrome(t)):
            if(is_prime(t)):
                print t
                break
        t=t+1
        
       
        
           
'''
def start():
    n = int (raw_input())
    print "is prime?",is_prime(n)
    #print "is palindrome?",is_palindrome(n)
   '''     
        
start()