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 generate_prime_palindromes(k):
	number=0
	number=6*k-1
	if check_prime(number) is True:
		return number
	number=6*k+1
	if check_prime(number) is True:
		return number

def check_prime(number):
	if check_palindrome(number) is False:
		return False
	else:
		counter=0
		square_root=int(sqrt(number))
		for i in range(2,square_root+2):
			if number%i==0:
				return False
			counter=counter+1
		if counter==square_root:
			return True

def check_palindrome(number):
	strnum=str(number)
	return strnum==strnum[::-1]

def main():
	k=1
	num=int(raw_input())
	while True:
		if num==1 or num==2:
			print '2'
			break
		elif num==3:
			print '3'
			break
		else:
			prime_num=generate_prime_palindromes(k)
			if prime_num>=num:
				print prime_num
				break
			k=k+1
	
if __name__=='__main__':
	main()