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
def prime(n):
    if n < 4:
        return True
    elif n % 2 == 0:
        return False
    elif n < 9 :
        return True
    elif n % 3 == 0:
        return False
    else:
        r = round(sqrt(n))
        f = 5
        while f <= r:
            if n % f == 0:
                return False
            elif n % (f+2) == 0:
                return False
            f = f + 6
    return True

no = int(raw_input())

i = no
while True:
    rev = 0
    num = i
    if no >= 98690:
        print '1003001'
        break

    while num != 0:
        rev = rev*10 + (num%10)
        num /= 10
    if rev == i:
        if prime(i):
            print i
            break
    i += 1