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
# cook your code here
import math
def prime(n):
    if n > 1:
        flag = 0 
        for i in xrange(2,int(math.sqrt(n))):
            if n%i == 0:
                flag = 1 
                break
        if flag == 0:
            return "Yes"
        else:
            return "No"
    else:
        return "No"
def palindrome(n):
    if str(n)[::-1] == str(n):
        return "Yes"
    else:
        return "No"
N = input()
while True:
    if N%2 != 0:
       if prime(N) == "Yes" and palindrome(N) == "Yes":
          print N
          break 
    N += 1