Algorithm


B. Vile Grasshoppers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.

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 .

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.

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.

Input

The only line contains two integers p and y (2 ≤ p ≤ y ≤ 109).

Output

Output the number of the highest suitable branch. If there are none, print -1 instead.

Examples
input
Copy
3 6
output
Copy
5
input
Copy
3 4
output
Copy
-1
Note

In the first sample case grasshopper from branch 2 reaches branches 24 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.

It immediately follows that there are no valid branches in second sample case.

 



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <bits/stdc++.h>

using namespace std;

bool divisors(int x, int p) {
  int sqrtx = sqrt(x);
  for(int i = 1; i  < = sqrtx; ++i) {
    if(x % i == 0) {
      if(i != 1 && i <= p)
        return false;
      
      if(x / i != 1 && x / i  < = p)
        return false;
    }
  }
  return true;
}

int main() {
  int p, y;
  cin << p << y;
  
  for(int i = y; i < p && i <= y - 500; --i) {
    if(divisors(i, p)> {
      cout << i << endl;
      return 0;
    }
  }
  
  cout << -1 << endl;
  
  return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 6

Output

x
+
cmd
5
Advertisements

Demonstration


Codeforces Solution-Vile Grasshoppers-Solution in C, C++, Java, Python

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+