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
#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      USER
#
# Created:     21-09-2015
# Copyright:   (c) USER 2015
# Licence:     <your licence>
#-------------------------------------------------------------------------------
z=input()
def prime(n):
    x = set()
    for a in range(2, n+1):
        if a not in x:
            yield a
            x.update(range(a*a, n+1, a))
l1=list(prime(100000))
if z>=98690:
    print "1003001"
for a in l1:
    s1=str(a)
    if a>=z and s1==s1[::-1]:
        print a
        break