eolymp
bolt
Try our new interface for solving problems
Problems

L. Lucky Primes

L. Lucky Primes

Stefan calls an positive integer p lucky prime, if p and number p1, obtained by reversing its decimal notation, i.e. reading all digits from end to beginning, are distinct primes.

Remind that positive integer is prime, if it has no positive integer divisors except for 1 and itself.

Given K , find K -th lucky prime.

Input

First line of the input contains one integer K (1 ≤ K ≤ 1000).

Output

If K -th lucky prime is not greater than 106 , print it. Otherwise print - 1.

Time limit 0.5 seconds
Memory limit 256 MiB
Input example #1
1
Output example #1
13
Source ACM-ICPC Ukraine 2015, 2nd Stage Ukraine, Saturday, September 12, 2015