//It's all about what U BELIEVE
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<bitset>
#include<vector>
#include<cstring>
#include<stdio.h>
#include<iostream>
#include<algorithm>
#define endl '\n'
#define PI acos(-1)
#define INF ~(1<<31)
#define pb push_back
#define pob pop_back
#define wtm while(t--)
#define wnm while(n--)
#define MOD 1000000007
#define lsone(Z) (Z&-Z)
#define gcu getchar_unlocked
#define allof(Z) Z.begin(),Z.end()
#define rallof(Z) Z.rbegin(),Z.rend()
#define mset(z,v) memset(z,v,sizeof(z))
#define lne if(line)puts("");else line =1
#define fo(s,y,z) for(int y=s ; y<(int)z ; y++)
#define readf freopen("/home/ebram96/Desktop/in" , "r" , stdin);
#define writef freopen("/home/ebram96/Desktop/out" , "w" , stdout);
using namespace std;
typedef unsigned long long ull;
typedef pair<ull,ull> pairull;
typedef pair<int,int> pairii;
typedef vector<string> vstr;
typedef deque<int> dqint;
typedef set<ull> setull;
typedef unsigned int ui;
typedef queue<int> qint;
typedef vector<int> vi;
typedef set<int> seti;
typedef long long ll;
//int dx[]={-1,0,1, 0,-1,1, 1,-1};
//int dy[]={ 0,1,0,-1, 1,1,-1,-1};
bool prime(int n)
{
int rt = sqrt(n);
for(int i = 3 ; i <= rt ; i+=2)if(n%i==0)
return 0;
return 1;
}
int main()
{
//readf
ll p , y;
cin>>p>>y;
y-=(y%2==0);
while(y > p)
{
if(prime(y))
{
printf("%lld",y);
return 0;
}
y-=2;
}
puts("-1");
}
Ly9JdCdzIGFsbCBhYm91dCB3aGF0IFUgQkVMSUVWRQojaW5jbHVkZTxtYXA+CiNpbmNsdWRlPHNldD4KI2luY2x1ZGU8c3RhY2s+CiNpbmNsdWRlPHF1ZXVlPgojaW5jbHVkZTxkZXF1ZT4KI2luY2x1ZGU8Y21hdGg+CiNpbmNsdWRlPGJpdHNldD4KI2luY2x1ZGU8dmVjdG9yPgojaW5jbHVkZTxjc3RyaW5nPgojaW5jbHVkZTxzdGRpby5oPgojaW5j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