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
import math
'''
code for testing and calculating prime palindrome
'''


def prime(val):
    limit = int(math.sqrt(val)+1)
    #print "limit ", limit
    for divisors in xrange(2, limit+1):
        if val % divisors == 0:
            #print "%d is not prime" %val
            return False
    else:
        # print "%d is prime" % val
        return True


def palindrome(test):
    num = test
    reverse_num = 0
    while num > 0:
        dividend = num % 10
        num /= 10  # collect quotient
        reverse_num = (reverse_num * 10) + dividend  # (quotient x 10) + dividend
    if test == reverse_num:
        return reverse_num


def test_prime_palindrome(num):
    done = False
    while not done:
        if prime(num) and palindrome(num):
            done = True
            return num
        else:
            num += 1

tst = input()
a = test_prime_palindrome(tst)
print a