937B.md (1599B)
1 Source: https://codeforces.com/problemset/problem/937/B 2 3 B. Vile Grasshoppers 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape. 22 23 The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (more precise, from 2 to *p*) are occupied by tiny vile grasshoppers which you're at war with. These grasshoppers are known for their awesome jumping skills: the grasshopper at branch *x* can jump to branches . 24 25 Keeping this in mind, you wisely decided to choose such a branch that none of the grasshoppers could interrupt you. At the same time you wanna settle as high as possible since the view from up there is simply breathtaking. 26 27 In other words, your goal is to find the highest branch that cannot be reached by any of the grasshoppers or report that it's impossible. 28 29 Input 30 31 The only line contains two integers *p* and *y* (2 ≤ *p* ≤ *y* ≤ 109). 32 33 Output 34 35 Output the number of the highest suitable branch. If there are none, print -1 instead. 36 37 Examples 38 39 Input 40 41 ``` 42 3 6 43 ``` 44 45 Output 46 47 ``` 48 5 49 ``` 50 51 Input 52 53 ``` 54 3 4 55 ``` 56 57 Output 58 59 ``` 60 -1 61 ``` 62 63 Note 64 65 In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5. 66 67 It immediately follows that there are no valid branches in second sample case.