Time

10:59:40
11 Feb 2012
ACM-ICPC Thailand Southern Region Programming Contest 2011
Left: 4 hours 1 minutes
End: 11.02.2012 15:00
Leader: Informatimukas
Five for week 22
Left: 11 hours 1 minutes
End: 11.02.2012 22:00
Leader: NuM
Version for print

Rabbit-failure

prb14

   On the stop we have N passengers, which Vanja and Peter were among, called at a trolleybus. The Vanja purchased a ticket the first. Peter glanced on the ticket and saw that the number of ticket is a prime number, and decided, that he must purchase a ticket with a simple number. Whether there is a chance at Peter to purchase a ticket to a next stop, if at a conductor only one roll of tickets, in the numbers of tickets is determined the amount by the bought ticket. In case if a roll is closed, Peter will stow "away", and he is expected by a failure.


Specifications

   Input

   An entrance line contains two numbers: amount of passengers and number of trolleybus ticket. The amount of numbers in the number of ticket does not exceed 6.

   Output

   Show out the amount of passengers, which it is necessary to skip Peter, to purchase a ticket with a simple number, or –1, if doing it is impossible.


Problem information

Time Limit: 1 seconds
Memory Limit: 64 MB
Balls for the passed test: 10
Complexity: 31% 236/342

Example

Example input

Test #1:
5 011
Test #2:
8  97

Example output

Test #1:
1
Test #2:
-1


← Spider and Fly Problems Mouse and corns →