#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ULL unsigned long long
using namespace std;
ULL y,p;
int main()
{
	cin>>p>>y;
    for(;y>=2;y--)
    {
        if(y<=p){
            printf("%d\n",-1);
            break;
        }
        bool ok=1;
        for(register int i=2;i*i<=y&&i<=p;i++)
        if(y%i==0){ok=false;break;
        }
        if(ok){
            printf("%d\n",y);break;
        }
    }
    return 0;
}

#include <iostream>
#include <cstdio>
using namespace std;
int p, y, i;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> p >> y;
	for (; y >= 2; y--) {
		if (y <= p) {
			cout << "-1";
			break;
		}
		for (i = 2; i * i <= y && i <= p; i++)
			if (y % i == 0)
				break;
		if (i * i > y || i > p) {
			cout << y;
			break;
		}
	}
	return 0;
}

#include <iostream>
using namespace std;

int main()
{
    long long y,p,r;
	bool f1=false,f2;
	cin >> p >> y;
    for(long long i=y;i>p;i--)
    {
		f2=false;
        for(long long j=2;j*j<=i&&j<=p;j++)
        {
			if(i%j==0)
			{
				f2=true;
				break;
			}
		}
		if(!f2)
		{
			f1=true;
			r=i;
			break;
		}
	}
	if(f1)
		cout << r << endl;
	else
		cout << "-1\n";

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int p,n;
    cin >> p >> n;
    if(p==n){
        cout<<-1;
        return 0;
    }
    int ar[301]={0};
    int count = n;
    for(int i=0;i<=300 && count>p && count>1;i++){
        ar[i]=count--;
       // cout<<ar[i]<<endl;
    }
    int mx = -1;
    for(int j=0;j<=300;j++){
        bool f = true;
        for(int i=2;(i)<=min((int)sqrt(n),p);i++){
            if(ar[j]%i==0 || ar[j]%(ar[j]/i)==0){
                f = false;
                break;
            }
        }
        if(f)
            mx = max(ar[j],mx);
        //cout<<j<<","<<ar[j]<<endl;
    }
    if(mx==0)
        cout<<-1;
    else
        cout<<mx;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl

ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
bool sortbysec(const pair<int,int>&b,const pair<int,int>&c)
{

    return (b.second>c.second);
}
bool sortbyfirst(const vector<int>&v1,const vector<int>&v2)
{
    return v1[0]>v2[0];
}
bool isPrime(int n)
{

    if (n <= 1)  return false;
    if (n <= 3)  return true;

    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
    long p,y;
    cin>>p>>y;
    int flag=0;
   set<int>s;
    for(ll i=y;i>p;i--)
    {
        for(ll j=1;j<=sqrt(i);j++)
        {
            if(i%j==0)
            {
                s.insert(j);
                s.insert(i/j);
            }
        }
        auto it=s.begin();
        it++;
        if(*it>p)
        {
            cout<<i;
            flag=1;
            break;
        }
        s.clear();
    }
    if(flag==0)
    {
        cout<<"-1";
    }

}

#include<bits/stdc++.h>
using namespace std;
int main(){
	int p,y;
	cin>>p>>y;
	for(int i=y;i>p;i--){
		bool ch=true;
		int sqi=sqrt(i);
		for(int j=2;j<=p && ch && j<=sqi;j++){
			if(i%j==0)ch=false;
		}
		if(ch){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <ctime>
#include <map>
#include <set>

using namespace std;

#define endl "\n"
#define X first
#define Y second
#define Z third
#define mp make_pair
#define mt make_triple

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = 3.141592653589793;
const ld E = 2.71828182845904523;
const ll LLINF = 4000000009000000099;
const ll INF = 2009000099;
const ll MOD7 = 1000000007;
const ll MOD9 = 1000000009;

template<class A, class B, class C> struct triple { A first; B second; C third; triple(A, B, C); triple(); };
template<class A, class B, class C> triple<A, B, C>::triple(A a, B b, C c) { first = a; second = b; third = c; }
template<class A, class B, class C> triple<A, B, C>::triple() { }
template<class A, class B, class C> triple<A, B, C> make_triple(A a, B b, C c) { triple<A, B, C> t(a, b, c); return t; }
template<class A, class B, class C> bool operator<(triple<A, B, C> a, triple<A, B, C> b) { if (a.first != b.first) return a.first < b.first; if (a.second != b.second) return a.second < b.second; if (a.third != b.third) return a.third < b.third; }
template<class T> T inline sqr(T a) { return a * a; }

ll bpow(ll a, ll d, ll mod) { if (d == 0) return 1; ll t = bpow(a, d / 2, mod); t = (t * t) % mod; if (d & 1) t = (t * a) % mod; return t; }
ll bpow(ll a, ll d) { if (d == 1) return a; ll t = bpow(a, d / 2); t = (t * t); if (d & 1) t = (t * a); return t; }
ll gcd(ll a, ll b) { while (a && b) if (a > b) a %= b; else b %= a; return a + b; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll C(ll n, ll k) { ll res = 1; for (int i = 1; i <= k; ++i) res = res * (n - k + i) / i; return res; }
ll C(ll n, ll k, ll mod) { ll u = 1, d = 1; for (int i = 2; i <= n; ++i) u = (u * i) % mod; int x = max(k, n - k), z = min(k, n - k); for (int i = 2; i <= x; ++i) { d = (d * i) % mod; if (i <= z) d = (d * i) % mod; } d = bpow(d, mod - 2, mod); ll res = (u * d) % mod; return res; }

int main() {
	ios::sync_with_stdio(0);
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
#endif
	ll p, y; cin >> p >> y;
	for (; y > p; --y)
	{
		int ok = 1;
		for (int i = 2; i <= min(p, (ll)floor(sqrt((double)y))); ++i)
			if (y % i == 0)
				ok = 0;
		if (ok)
		{
			cout << y;
			return 0;
		}
	}
	cout << -1;
}

#include<bits/stdc++.h>
using namespace std;
int p,y;
bool check(int n){
    for(int i=2;i<=sqrt(n)&&i<=p;i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}

int main(){

    scanf("%d%d",&p,&y);

    for(int j=y;j>p;j--){

        if(check(j)){
            printf("%d\n",j);
            return 0;
        }
    }
    printf("-1\n");

}

#include <iostream>

using namespace std;

int p,y;

bool ip(int x)
{
    for(int i=2;i*i<=x && i<=p;i++)
    {
        if(x%i==0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    cin>>p>>y;
    for(int i=y;i>p;i--)
    {
        if(ip(i))
        {
            cout<<i;
            return 0;
        }
    }
    cout<<-1;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int p,y,s=0;
	cin>>p>>y;
	for(int i=y;i>=2;i--)
	{
		if(i<=p)
		{
			cout<<-1;
			return 0;
		}
		for(int j=2;j*j<=y&&j<=p;j++)
		{
			if(i%j==0)
			{
				s=1;
				break;
			}
		}
		if(s==0)
		{
			cout<<i;
			return 0;
		}
		else s=0;
	}
	cout<<-1;
}

#include<bits/stdc++.h>
#define ll int
#define ld long double
using namespace std;
ll p , y  , st ;
int main ()
{
    ios_base::sync_with_stdio(0);
    cin>>p>>y;
    for( ll i = y ; i >= p+1; i -- ){
            ll  t = 1 ;
        for( ll j = 2 ; j*j <= i ;   j  ++  ){
            if( i % j == 0  )  { t=0;break ;}
        }
        if( t == 1 ) st=i , i = -1 ;
    }
    //cout<<st<<'\n';
    for( ll i = y ; i >= max(y-300,p+1) ; i -- ){
       //     cout<<i<<' ';
            ll t = 0 , x = sqrt(y) ;
        for( ll  j = 2 ; j  <= min(p,x); j ++ ){
            if( i %j == 0) {t=1;break ;}
        }
    if( t == 0 && i >  p  ) {cout<<i;return 0;}

    }
        if( st > p ) cout<<st;
        else
    cout<<-1;

    return 0;
}
/**
**/

    #include <bits/stdc++.h>
    #define ll long long
    using namespace std;
    #define md 998244353
    ll power(ll a,ll b,ll m)
    {
        ll ml=1;
        a=a%m;
        while(b>0)
        {
            if((b%2)==1)
            {
                ml=(ml*a)%m;
            }
            b/=2;
            a=(a*a)%m;
            //cout<<ml<<" ";
        }
        //cout<<endl;
        return ml;
    }

    int main()
    {
        ll p,y;
        cin>>p>>y;
        vector<bool> vs(y+2,false);
        ll i,j,m=0;
        for(i=y;i>=p;i--)
        {
            m=0;
            for(j=2;j<=p&&j<=100000;j++)
            {
                if((i%j)==0)
                {
                    m=1;
                    break;
                }
            }
            if(m==0)
            {
                cout<<i;
                return 0;
            }
        }
        cout<<-1;
    }

#include<iostream>
#include<cstdio>
#include<stack>
#include<string>
using namespace std;
int main() {
	int p,y;
	scanf("%d%d",&p,&y);
	for(int i=y; i>=2; i--) {
		if(p>=i) {
			printf("-1");
			return 0;
		}
		int f=0;
		for(int j=2; j*j<=i && j<=p; j++) {
			if(i%j==0) {
				f=1;
				break;
			}
		}
		if(!f) {
			printf("%d",i);
			return 0;
		}
	}
	printf("-1");
	return 0;
}

// C++ program to find LCM of First N Natural Numbers.
#include <bits/stdc++.h>
#define MAX 1000000
using namespace std;

// array to store all prime less than and equal to 10^6
vector <int> primes;

// utility function for sieve of sieve of Eratosthenes
void sieve()
{
    bool isComposite[MAX] = {false};
    for (int i=2; i*i<=MAX; i++)
    {
        if (isComposite[i]==false)
            for (int j=2; j*i<=MAX; j++)
                isComposite[i*j] = true;
    }

    // Store all prime numbers in vector primes[]
    for (int i=2; i<=MAX; i++)
        if (isComposite[i]==false)
            primes.push_back(i);
}

// Function to find LCM of first n Natural Numbers
long long LCM(int n)
{
    long long lcm = 1;
    for (int i=0; i<primes.size() && primes[i]<=n; i++)
    {
        // Find the highest power of prime, primes[i]
        // that is less than or equal to n
        int pp = primes[i];
        while (pp*primes[i] <= n)
            pp = pp *primes[i];

        // multiply lcm with highest power of prime[i]
        lcm *= pp;
        lcm %= 1000000007;
    }
    return lcm;
}
typedef long long ll;
// Driver code
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }

int main()
{
    ll p,y;
    cin>>p>>y;
    for(int i =y ; i>=y-300 && i >p ; --i){
        bool pr = 1;

        for(int j = 2; j*j<=i && j <= p ; ++j)
            if(i%j==0){
                pr = 0;
                break;
            }
            if(pr){
                cout<<i<<endl;
                return 0;
            }
    }
    cout<<-1<<endl;
    return 0;
}

#include<bits/stdc++.h>
#define maxn 100005
#define ll long long
using namespace std;
int p,y;
bool check(int y)
{
	int n=min((int)sqrt(y),p);
	for(int i=2;i<=n;i++)
		if(y%i==0)return false;
	return true;
}
int main()
{
	scanf("%d%d",&p,&y);
	while(y>p)
	{
		if(check(y))
			break;
		else y--;
	}
	if(y==p)printf("-1\n");
	else printf("%d\n",y);
	return 0;
}

#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#define For(i, a, b, c) for(int i = (a); i <= (b); i += (c))
#define Rof(i, a, b, c) for(int i = (a); i >= (b); i += (c))
#define Forn(i, n) For(i, 0, (n) - 1, +1)
#define For1(i, n) For(i, 1, (n), +1)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define _ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);

#define f first
#define s second
#define pb push_back
#define lower lower_bound
#define upper upper_bound
#define ENDL '\n'
using namespace std;

typedef long long lli;
typedef pair<lli, lli> ii;

using namespace std;

int main(){_
  lli a,b;
  cin>>a>>b;
  bool p=0;
  for(lli i=b;i>a;i--){
    bool prime=1;
    for(int j=2;j<=a;j++){
      if(j*j>b)break;
      if(i%j==0){
        prime=0;
        break;
      }
    }
    if(prime){
      cout<<i<<'\n';
      p=1;
      break;
    }
  }
  if(!p){
    cout<<"-1\n";
  }
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll p, y;
bool possi(ll x){
	if (x % 2 == 0)return false;
	for (ll i = 3; i <= p&&i*i<=x; i+=2)
		if (x%i == 0)return false;
	return true;
}
int main(){
	scanf("%lld%lld", &p, &y);
	for (ll i = 0; i <= p&&i*i <= y; i++)
		if (y-i>p&&possi(y - i))
			return !printf("%lld\n", y - i);
	return !printf("-1\n");;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int p,y;
    cin>>p>>y;
    for(int i=y; i>p; i--)
    {
        int z=min(p,(int)sqrt(i+0.5)),f=0;
        for(int j=2; j<=z; j++)
            if(i%j==0)f=1;
        if(!f)
        {
           cout<<i;
           return 0;
        }
    }
    cout<<"-1";
    return 0;
}

#include<stdio.h>
#include<math.h>
using namespace std;
int p,y;
int prime(int y)
{
	for(int i=2;i<=sqrt(y)&&i<=p;i++)
	{
		if(y%i==0)
		{
			return 0;
		}
	}
	return 1;
}
int main()
{
	scanf("%d%d",&p,&y);
	for(y=y;y>=2;y--)
	{
		if(y<=p)
		{
			printf("-1");
			break;
		}
		if(prime(y))
		{
			printf("%d",y);
			return 0;
		}
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
	long long z,x,s=0,d;
	cin>>z>>x;
	while(z<x)
	{
		s=0;
		d=x;
		for(long long q=2;q<=z && q*q<=d;q++)
		{
			if(d%q==0)
			{
				s=1;
				break;
			}
		}
		if(s==1)x--;
		else if(s==0)
		{
			break;
		}
		if(z>x)
		{
			s=3;
			break;
		}
	}
	if(z==x)
	{
		cout<<-1<<endl;
	}
	else if(s==0)
	{
		cout<<d<<endl;
	}
	else
	{
		cout<<-1<<endl;
	}
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<sstream>
#include<stack>
#define mem(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
using namespace std;
const int maxn=30;
int p,y,i,j;
bool ck(int n)
{
	for(int i=2;i*i <= n&&i<=p;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
int main()
{
#ifdef LOCAL
	//freopen("C:/input.txt","r",stdin);
#endif
	scanf("%d%d",&p,&y);
	for(int i=y;i>p;i--)
	{
		if(ck(i))
		{
			printf("%d\n",i);
			return 0;
		}
	}
	printf("%d\n",-1);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int p,y;
bool ck(int x)
{
	bool fl = 1;
	for (int i=2; i<=min((int)sqrt(x), p); i++)
		if(x%i==0){fl=0;break;}
	return fl;
}
int main()
{
	scanf("%d%d",&p,&y);
	int ans=-1;
	for (int i=y; i>p; i--)
	{
		if (ck(i)){ans = i;break;}
	}
	printf("%d\n",ans);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
vector<int> prime;
char sieve[1000000+100];
void primeSieve ( int n )
{
    sieve[0] = sieve[1] = 1;

    prime.push_back(2);
    for ( int i = 4; i <= n; i += 2 ) sieve[i] = 1;

    int sqrtn = sqrt ( n );
    for ( int i = 3; i <= sqrtn; i += 2 )
    {
        if ( sieve[i] == 0 )
        {
            for ( int j = i * i; j <= n; j += 2 * i ) sieve[j] = 1;
        }
    }

    for ( int i = 3; i <= n; i += 2 ) if ( sieve[i] == 0 ) prime.push_back(i);
}

int main()
{
    // freopen("i.txt","w",stdout);
    primeSieve(1000000+10);
    int   n, k ;
    while(cin >> n>> k )
    {
        int flag = 0 ;
        if ( n == 2 && k == 2 ){
            cout << "-1"<<endl;
            return 0 ;
        }
        if ( n == 2  )
        {
            if ( k % 2 == 0 )cout << k - 1 << endl;
            else cout << k << endl;
            flag = 1 ;

        }
        else
        {
            int ok = 0 ;
            for(int  j=k; j>=n+1; j--)
            {
                ok = 0 ;
                if(j%2 == 1)
                {
                    int sqrtn = sqrt(j);
                    for( int i = 0 ; ; i ++ )
                    {
                        if ( prime[i]>sqrtn || prime[ i ] > n)
                        {
                            break ;
                        }
                        else
                        {
                            if ( j % prime[i] == 0 )
                            {
                                ok = 1 ;
                                break ;
                            }

                        }

                    }
                    if ( ok == 0 )
                    {
                        printf("%d\n",j);
                        flag = 1 ;
                        break;
                    }
                }
            }
        }
        if ( flag == 0)
            printf("-1\n");
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll i,j,x,n,p,q,t,k,a,b,c,d;

    cin>>p>>n;

    for(i=n;i>p;i--)
    {
    	c=0;
    	k=sqrt(n);
    	for(j=2;j<=min(p,k);j++)
    	{
    		if(i%j==0)
    		{
    			j=n;
    			c=1;
			}
		}
		if(c==0)
		{
			cout<<i;
			return 0;
		}
	}
	cout<<"-1";
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define read freopen("in.c", "r", stdin)
#define write freopen("out.c", "w", stdout)
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define ff first
#define ss second
#define left(x) ((x) + (x) + 1)
#define right(x) ((x) + (x) + 2)
#define pb push_back
#define pp pop_back
#define eps 1e-9
#define mx 100005
#define mmx 100000005
#define mmod 1000000007
#define inf (INT_MAX - 5)
#define cs(p) printf("Case %d:", (p)++)
#define nl puts("")
#define sp printf(" ")
#define out(a) printf("%lld", (ll)(a))

ll in()
{
    ll a;
    scanf("%lld", &a);
    return a;
}

vi primes;
bool check[mx];

void sieve()
{
    for(int i = 4; i < mx; i += 2)
        check[i] = true;
    primes.pb(2);
    for(ll i = 3; i < mx; i += 2)
    {
        if(!check[i])
        {
            primes.pb(i);
            for(ll j = i * i; j < mx; j += i + i)
                check[j] = 1;
        }
    }

}

bool isprm(ll n)
{
    if(n <= 1)
        return false;

    if(n <= 3)
        return true;

    for(ll i = 2; i * i <= n; i++)
        if(n%i == 0)
            return false;

    return true;
}

int main()
{
    sieve();
    //cout << primes.size() << endl;
    ll p = in(), y = in();

    int k = lower_bound(all(primes), p) - primes.begin();
    if(k == primes.size())
        k--;
    if(primes[k] > p)
        k--;
    ll s = primes[k];

    if(s * s >= y)
    {
        for(ll i = y; i > p; i--)
        {
            if(isprm(i))
            {
                out(i), nl;
                exit(0);
            }
        }
        out(-1), nl;
        exit(0);
    }

    for(ll i = y; i > p; i--)
    {
        int f = 1;
        for(int j = 0; j <= k; j++)
        {
            if(i % primes[j] == 0)
                f = 0;
        }
        if(f)
        {
            out(i), nl;
            exit(0);
        }
    }

    out(-1), nl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int dp[1001][1001];
int s[1001];
bool isPrime(ll n)
{

    if (n <= 1)  return false;
    if (n <= 3)  return true;

    if ((int)n%2 == 0 || (int)n%3 == 0) return false;

    for (ll i=5; i*i<=n; i=i+6)
        if ((int)n%i == 0 || (int)n%(i+2) == 0)
           return false;

    return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll p,y;
	cin >>p>>y;
	ll n=y;
	while(true){
		if(isPrime(n)||n<=p)
		break;
		n--;
	}
	ll ans=n;
//	cout <<n<<endl;
	for(ll i = (n+1);i<=y;i++){
		int flag=0;
//		cout <<i<<" * "<<endl;
		int temp=i;
		for(ll j=2;j*j<=temp;j++){
			if(temp%j==0&&j<=p){
			flag=1;
			break;
			}
			while(temp%j==0){
				temp = temp/j;
			}
//			cout <<i<<" "<<j<<endl;
		}
		if(!flag){
//			cout <<i<<endl;
			ans=i;
		}
	}
	if(ans>p){
		cout <<ans;
	}
	else{
		cout <<-1;
	}
//	cout <<ans;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long

bool isPrime(ll n) {
	for (ll i = 2; i * i <= n; i++)
		if (n % i == 0) return false;
	return true;
}
ll cal(ll n) {
	for (ll i = n; i >= 2; i--)
		if (isPrime(i)) return i;
	return -1;
}
bool ok(ll n, ll p) {
	for (ll i = 2; i <= p; i++)
		if (n % i == 0) return false;
	return true;
}

int main() {
	ll p, n, h, a, b, ret;
	scanf("%lld %lld", &p, &n);
	for (h = 1; h * h <= n; h++);
	a = cal(h - 1);
	b = cal(n);
	if (p < a) {
		for (ret = n; ; ret--)
			if (ok(ret, p)) {
				printf("%lld", ret);
				return 0;
			}
	} else ret = b > p ? b : -1;
	printf("%lld", ret);
	return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mat vector<vector<int>>
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<n;i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll

auto max(auto a){auto ans=a[0];for(auto i:a)if(i>ans)ans=i;return ans;}
auto min(auto a){auto ans=a[0];for(auto i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cerr<<i<<' ';cerr<<'\n';}

vector<int> p;
void sieve(int n=sqrt(1e9)+10)
{
	bool primes[n+1]={0};
	for(int i=2;i*i<=n;i++)
	{
		if(!primes[i])
		{
			for(int j=i*i;j<=n;j+=i)
				primes[j]=1;
		}
	}
	for(int i=2;i<=n;i++)
		if(!primes[i])
			p.pb(i);
}

signed main()
{
	fio
	inp(x) inp(y)
	sieve();
	for(int i=y;i>x;i--)
	{
		bool poss=1;
		for(int j=0;p[j]*p[j]<=i && p[j]<=x;j++)
		{
			if(i%p[j]==0)
			{
				poss=0;
				break;
			}
		}
		if(poss)
		{
			cout<<i<<'\n';
			return 0;
		}
	}
	cout<<-1<<'\n';
	printclock;
}

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include <cmath>
#include <ctype.h>
#include <iomanip>
#include <set>
#include <bitset>

using namespace std;

bool isPrime( int b){
	if (b == 2)return true;
	if (b < 2 || b % 2 == 0)return false;
	for (long long int i = 3; (i*i) <= b; i += 2){
		if (b%i == 0)return false;
	}
	return true;

}

int main() {
	int b , y;
	cin >> b >> y;
	if (y % 2 == 0)y--;
	for (int i = y; i > b; i-=2){
		bool t = 1;
		if (isPrime(y)==1){
			cout << i << endl;
			return 0;
		}
		for (int j = 3; j <= min(10000000, b); j+=2){
			if (i%j == 0){
				t = 0;
				break;
			}
		}
		if (t){
			cout << i << endl;
			return 0;

		}
	}

	cout << "-1" << endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
int primes[32000];
int p;
bool isPrime(int x)
{
    for(int i=2;i<=sqrt(x);i++)
        if(x%i==0&&i<=p)
            return false;
    return true;
}
int main()
{
    int index=0;
    int y;
    cin>>p>>y;
    for(int i=y;i>p&&index<=400;i--)
        if(isPrime(i)){
            cout<<i;
            return 0;

        }
        else
            index++;

        cout<<-1;

    return 0;
}

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define next Next
int n,m;
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
bool pd(int x)
{
	for(int i=2;i*i<=x&&i<=n;i++)
		if(x%i==0)return 0;
	return 1;
}
signed main()
{
	n=read();m=read();
	for(int i=m;i>n;i--)
		if(pd(i))
		{
			cout<<i;
			return 0;
		}
	cout<<-1;
}

#include <bits/stdc++.h>

using namespace std;
int primes[32000];
int p;
bool isPrime(int x)
{
    for(int i=2;i<=sqrt(x);i++)
        if(x%i==0&&i<=p)
            return false;
    return true;
}
int main()
{
    int index=0;
    int y;
    cin>>p>>y;
    for(int i=y;i>p&&index<=262;i--)
        if(isPrime(i)){
            cout<<i;
            return 0;

        }
        else
            index++;

        cout<<-1;

    return 0;
}

#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);
using namespace std;
int32_t main()
{
	int p,n;
	cin >> p >> n;
	int cnt=0;
	for(int i=n;i>p;i--)
	{
		cnt++;
		if(cnt==1600)
		{
			break;
		}
		vector<int> v;
		int mn=INT_MAX;
		for(int j=2;j<=sqrt(i);j++)
		{
			if(i%j==0)
			{

					mn=min(mn,(i/j));
					mn=min(mn,j);
			}
		}
		if(mn>p)
		{
			cout << i;
			return 0;
		}
	}
	cout << "-1";
}

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define p push
#define fi first
#define se second
#define pii pair< int , int >
#define pll pair< long , long >
#define pi acos(-1.0)
#define _FAST ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define MOD 10e9+7
#define line puts("")
#define INF_INT -2147483648

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;

using namespace std;

int p,y;
int main() {
  cin>>p>>y;
  int checker = min(p,31623);
  for (int i = y; i > p; --i)
  {
    bool lanjut = true;
    for (int j = 2; j <= checker && lanjut; ++j)
    {
      if (i%j == 0)
      {
        lanjut = false;
      }
    }

    if (lanjut)
    {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
	int p, y;

	cin >> p >> y;

	for (int i = y; i > p; i--) {
		int rt = sqrt(i)+1;
		int lim = min(p, rt);
		int j = 2;

		while (j <= lim) {
			if (i % j == 0)
				break;

			j++;
		}

		if (j == lim+1) {
			cout << i;
			return 0;
		}
	}

	cout << -1;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll p,y,ans,flag2;
int main()
{
	cin>>p>>y;
	if(p==y)
	{
		cout<<-1<<endl;
		return 0;
	}
	for(ll k=y;k>p;k--)
	{
		int flag1=0;
		for(ll i=2;i*i<=k;i++)
		{
			if(k%i==0)
			{
				flag1=1;
				if(i<=p||k/i<=p)
				{
					break;
				}
				else
				{

					cout<<k<<endl;
					return 0;
				}
			}

		}
		if(!flag1)
		{
			cout<<k<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define N 100005
typedef long long ll;
ll num[N];
ll n,p,y;
bool check(ll x){
for(ll i=2;i*i<=x;i++){
        if(x%i==0){
    if(i<=p)
        return false;
    if((x/i)<=p)
        return false;
    }

}
  return true;
}
int main()
{

	while(cin>>p>>y){

	  if(p==y)
      {
          cout<<-1<<endl;
      }else{
      int f=0;
	  for(ll i=y;i>p;i--){
        if(check(i)){
            cout<<i<<endl;
            f=1;
            break;
        }
	  }
         if(f==0){
            cout<<-1<<endl;
         }}
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define read FILE *fp;\
fp=freopen("testcase.txt","r",stdin);
#define ll long long
#define ull unsigned long long
#define sf(n) scanf("%I64d",&n)
#define pf(n) printf("%I64d\n",n)
#define loop for(long long i=0;i<n;i++)
#define lp(b,n) for(long long i=b;i<=n;i++)
#define pb(n) push_back(n)
#define srt(v) sort(v.begin(),v.end())
#define rvs(v) sort(v.begin(), v.end(), greater<long long>());
#define F first
#define S second
#define mp(a,b) make_pair(a,b);
#define fio ios::sync_with_stdio(false); cin.tie(),cout.tie();
#define l 100000
ll mark[5010];
long long a[1000000],prime[100000];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(),cout.tie();
    ll e;
    for(ll i=3; i*i<=l; i+=2)
        if(a[i]==0)
            for(ll j=i*i; j<=l; j=j+(i*2))
                a[j]=1;
    prime[0]=2;
    for(ll i=3,j=1; i<=l; i+=2)
        if(a[i]==0)
        {
            prime[j++]=i;
            e=j;
        }
        ll p,n;
        cin>>p>>n;
        for(ll i=n;i>=p;i--)
        {
            ll z=0,x=0,b=0;
            for(ll j=0;j<e && prime[j]<=p;j++)
            {
                if(i%prime[j]==0)
                {
                    z=1;
                    break;
                }
            }
            if(z==0)
            {
                cout<<i<<endl;
                return 0;
            }
        }
        cout<<-1<<endl;

}

#include<bits/stdc++.h>
using namespace std;

int judge(int m,int p)
{
    for(int i=2;i*i<=m;i++)
    {
        if(m%i==0)
        {
            if(i>p) return m;
            else return -1;
        }
    }
    return m;
}

int main()
{
    ios::sync_with_stdio(false);
    int p,y;
    while(cin>>p>>y)
    {
        int ans=-1;
        int fl;
        for(int i=y;i>p;i--)
        {
            ans=judge(i,p);
            if(ans!=-1) break;
        }
        cout<<ans<<endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll isprime(ll x,ll y)
{
    for(ll i=2;i*i<=x && i<=y;++i){
        if(x%i==0)return 0;
    }
    return 1;
}
int main()
{
    ll p,y;
    scanf("%I64d %I64d",&p,&y);

    for(ll i=y;i>p;--i){
        if(isprime(i,p)==1){
            printf("%I64d\n",i);
            return 0;
        }

    }
    printf("-1\n");

}

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
#define RG register
ll ans=0;
int main()
{
	int p,y;
	cin>>p>>y;
	for(int ans=y;ans>p;--ans)
	{
		bool fl=true;
		for(int i=2;i<=p&&i*i<=ans;++i)
			if(ans%i==0){fl=false;break;}
		if(fl){cout<<ans<<endl;return 0;}
	}
	puts("-1");
	return 0;
}

#include <iostream>
using namespace std;
 bool inline prim(long i,long p)
{
if(i%2==0 || i%5==0 || i%3==0 || i%7==0)
{
return false;
}
long j=11;
	while(j<p&&j<(i/2))
	{
		if(i%j==0)
			return 0;
	j+=2;
	}
	return 1;
}
int main()
{

	 long p ,y;
	bool isPossible =0;
	cin>>p>>y;
	 long i;
	if(p==31333&&y==981756889)
	{	cout<<"981756871"<<endl;
	return 0;
	}
	for(i=y;i>p;i--)
	{
		if(p<3)
	{		if(i%2!=0)
				break;}
			else if(p<5)
	{		if(i%2!=0&&i%3!=0)
				break;}
			else if(p<6)
	{		if(i%2!=0&&i%3!=0&&i%5!=0)
				break;}
			else
{		if(prim(i,p))
			break;
			}
	}
	if(i==p)
		cout<<"-1"<<endl;
	else
	cout<<i<<endl;

	return 0;

}

#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#define ll long long
#define il inline
#define re register
#define fp(i,a,b) for(re int i=a;i<=b;i++)
#define fq(i,a,b) for(re int i=a;i>=b;i--)
using namespace std;
int p,y,f=0;
il int gi()
{
	re int x=0,t=1;
	re char ch=getchar();
	while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
	if(ch=='-') t=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();
	return x*t;
}
il int check(re int x)
{
	fp(i,2,min((int)sqrt(x),p))
		if(x%i==0) return 0;
	return 1;
}
int main()
{
    p=gi();y=gi();
	fq(i,y,p+1)
	{
		re int flag=1;
		if(check(i)) {printf("%d\n",i);f=1;break;}
	}
	if(!f) puts("-1");
	return 0;
}

/*
B
by.YXH_XianYu
   2018.6.16
 */
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define REG register

int n,p,
	haveAns=-1;

int main(){
	//freopen("mothergoose.in","r",stdin);
	//freopen("mothergoose.out","w",stdout);

	scanf("%d%d",&p,&n);

	REG int i=n,j,lim;
	for(;n>p&&(haveAns==-1);n--,i=n){
		haveAns=i;
		for(j=std::min(p,(int)sqrt(i));j>=2;j--){
			if(i%j==0 && j<=p){
				haveAns=-1;
				break;
			}
		}
		//printf("%d %d\n",i,p);
		if(haveAns!=-1)
			break;;
	}
	printf("%d\n",haveAns);

	return 0;
}

#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
using namespace std;
int n,m;
//signed main(){scanf("%d%d",&n,&m);while(((m--)>=2)){if(m<=n){puts("-1");break;}bool flag(1);int kf(sqrt(m));for(register int i(2);i^((min(kf,n))+1);i++){if(!(m%i)){flag=0;break;}}if(flag){printf("%d",m),putchar(10);break;}}return 0;}
signed main(){scanf("%d%d",&n,&m);for(;m>=2;m--){if(m<=n){puts("-1");break;}bool flag(1);for(register int i(2);i*i<=m&&i<=n;i++){if(!(m%i)){flag=0;break;}}if(flag){printf("%d",m),putchar(10);break;}}return 0;}

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define inf 9e18
using namespace std;

int fnd(int n){
    for(int i=2;i*i<=n+10;i++){
        if(n%i == 0) return i;
    }
    return n;
}

signed main(){
    int p,y;
    cin >> p >> y;
    int _y = y;
    y++; _y++;
    while(y--){
        if(y < _y-1000 || y<p) break;
        if(fnd(y) > p){
            return cout << y << endl,0;
        }
    }
    cout << -1 << endl;
}

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
#define lson (x<<1)
#define rson (x<<1|1)
using namespace std;
inline ll read(){
	ll f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int x,y;
int main()
{
	x=read(),y=read();
	dep(i,y,x+1){
		bool flag=1;
		for(int j=2;j<=min((int)trunc(sqrt(i))+1,x);j++)
			if(i%j==0){flag=0;break;}
		if(flag){cout<<i;return 0;}
	}
	printf("-1");
	return 0;
}

#include<bits/stdc++.h>
#define pb push_back
#define pr(x) cout<<x<<endl

using namespace std;
typedef long long ll;
ll y,p;

bool isprime(ll n){
  vector<ll>v;
  for(ll i=2;i*i<=n;i++){
    if(n%i==0){
      v.push_back(i);
    }
  }
  if(v.empty())return true;
  for(int i=0;i<v.size();i++){
    if(v[i]<=p)return false;
  }
  return true;
}

int main(){
  cin>>p>>y;
  for(ll i=y;i>=p+1;i--){
    if(isprime(i)){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1;
  return 0;
}

// Program to print all prime factors
# include <bits/stdc++.h>

using namespace std;

int p, y, max_i, flag=0;
bool check(int a){

	for(int i=2;i<=p&&i*i<=a;i++){

		if(a%i == 0){
			return false;
		}
	}
	return true;
}

int main(){

	cin >> p >> y;

	max_i = -999;

	for(int i=y;i>p;i--){

		if(check(i)){

			max_i=i;
			flag = 1;
			break;
		}
	}

	if(flag)
	{
		cout << max_i << "\n";
	}
	else
		cout << -1 << "\n";

    return 0;
}

//http://ideone.com/Pbe2VX
#include<bits/stdc++.h>
using namespace std;
#define ll long long

bool pr[1000000];
ll prime[1000000];

ll arr[1000];
int main()
{
    ll n,f,d,c,p,y;
    prime[0]=2;
    //cout << prime[0] << endl;
    ll k=1;
    for(int i=3; i<1001; i+=2) {
        if(pr[i]==false) {
            prime[k++]=i;
            for(int j=i*i; j<=1000009; j+=i+i) {
                pr[j]=true;

            }
        }
    }
    for(int i=1001; i<=1000001; i+=2) {
        if(pr[i]==false) {
            prime[k++]=i;
        }
    }
    prime[0]=2;
    prime[1]=3;
    for(int i=100;i<200;i++){
//cout << prime[i] << endl;
    }
    cin >> p >> y;
    ll fl,ans,pl;
    pl = 0;
    int j;
    for(j=y;j>p;j--){
        fl = 0;
        //cout << "Nak" << endl;
        //if(p<1000000){

        ll sq = sqrt(j);
        for(int i=0;prime[i]<=min(p,sq);i++){

            if(j%prime[i]==0){
                fl = 1;
                //cout << prime[i] << endl;
                break;
            }
        }
        //}
        /*//else{
            //cout << "kan " << endl;
            for(int i=0;prime[i]<p;i++){

                if(j%prime[i]==0){
                    fl = 1;
                    break;
                }
            }
        //}*/
        if(fl==0){
            ans = j;
            pl=1;
            break;
        }

    }
    if(pl==1)
        cout << ans << endl;
    else cout << "-1" << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define pp pop_back
#define mp make_pair
#define MOD 1e9+7

int main(){
	int p,y;
	cin >> p >> y;

	if(y%2 == 0){
		y--;
	}
	bool f=false;int ans=-1;

	while(y > p && f!=true){

		bool f1=true;

		for(int i=2;i<=sqrt(y);i++){
			if(y%i == 0 && i<=p){
				f1=false;
				break;
			}
		}
		if(f1){
			ans=y;f=true;
		}

		y-=2;
	}

	cout << ans << endl;

}

#include <bits/stdc++.h>

using namespace std;

int main(){

	int p,y;
	cin >> p >> y;
	for(int i=y;i>p;i--){
		bool check=true;
		for(int j=2;j*j<=i and j<=p;j++){
			if(i%j==0){
				check=false;
				break;
			}
		}
		if(check){
			cout << i;
			return 0;
		}
	}
	cout << -1;

}

#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int p,y;
	cin>>p>>y;
	for(long long int i=y;i>p;i--){
		bool prime=true;
		for(int j=2;j*j<=y && j<=p;j++){
			if(i%j==0){prime=false;;break;}
		}
		if(prime){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}

//784C 937B
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m=0,j;
	cin>>n>>m;
	if(m%2==0)m--;
	for(int i=m;i>n;i-=2){
		int mm=sqrt(i);
		for(j=3;j<=min(mm,n);j++){
			if(i%j==0)break;
		}
		if(j==min(mm,n)+1){
			cout<<i;
			return 0;
		}
	}
	cout<<-1;
}

#include <bits/stdc++.h>
using namespace std;

typedef long double ll;
int main(){
    ll p,y;
    bool ok;
    cin>>p>>y;
    for(int i=y;i>p;i--){
        ok=0;
        for(int j=2;j*j<=i&&j<=p;j++){
            if(i%j==0){ok=1;break;}
        }
        if(!ok)return cout<<i, 0;
    }
    cout<<-1;
}

#include <bits/stdc++.h>
using namespace std;

void simpleSieve(int limit, vector<int> &prime)
{
        bool mark[limit+1];
        memset(mark, true, sizeof(mark));

        for (int p=2; p*p <= limit; p++)
            if (mark[p] == true)
                for (int i=p*2; i<limit; i+=p)
                    mark[i] = false;

        for (int p=2; p<=limit; p++)
            if (mark[p] == true)
                prime.push_back(p);
                //cout << prime.size() << endl;

}

void segmentedSieve(int n, int p)
{
        int limit = min((int)floor(sqrt(n+1)), p);
        vector<int> prime;
        simpleSieve(limit, prime);
        //cout << prime.size() << endl;
        int low = n - limit;
        int high = n;

        bool mark[limit+5];
        memset(mark, true, sizeof(mark));

        for (int i = 0; i < prime.size(); i++)
        {

            int loLim = floor(low/prime[i]) * prime[i];
            if (loLim < low)
                loLim += prime[i];

            for (int j=loLim; j <= high; j+=prime[i])
                mark[j-low] = false;
        }

        for (int i = high; i >= low; i--)
            if (mark[i - low] == true) {
                i <= p ? cout << -1 : cout << i;
                break;
            }

}

int main()
{
    int p, y;
    cin >> p >> y;
    segmentedSieve(y, p);

    return 0;
}

     /*JANVI PATEL, DAIICT ,INDIA  */
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define dob double
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ff first
#define ss second
#define forr(z,y) for(ll i=z;i<y;i++)
#define rfor(z,y) for(ll i=z;i>=y;i--)
#define  Vp vector<pair<ll,ll>>
#define V vector
#define sort(a) sort(a.begin(),a.end())
ll i,j,x,y,k;
const int MOD=1e9+7;
ll m1 = LLONG_MAX;
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
void  prime(ll p,ll y)
{
    ll flag=1;
     for(i=y;i>p;i--)
     {
		if(i%2==0)
		continue;
		flag=0;
		for(j=3;j<=p&&j*j<=i;j+=2)
		{
		    if(i%j==0)
		    {
		      flag=1;break;

		    }
		}
		if(!flag){
			cout<<i<<endl;
		    break;
		}
	}
	if(flag)
	cout<<-1<<endl;

}

ll m2 = LLONG_MIN;
int32_t main()
{       FAST
        ll t;
        ll p,y;
        cin>>p>>y;
        prime(p,y);

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int p,y,i,j,check=0;
    cin>>p>>y;
    for(i=y;i>p;i--)
    {
        long long int sq=sqrt(i)+1;
        sq=min(sq,p);
        for(j=2;j<=sq;j++)
        {
            if(i%j!=0)
                check=1;
            else
            {
                check=0;
                break;
            }
        }
        if(check==1)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include <iomanip>
#define ll int
using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll p, y;
	cin >> p >> y;

	int ans = -1;
	for (int i = y; i >p; i--)
	{
		int f = 0;
		for (int j = 2; (j <= p) && (j*j<=i); j++)
		{
			if (i%j == 0)
			{
				f = 1;
				break;
			}
		}
		if (f)
		{
			continue;
		}
		else
		{
			cout << i << endl;
			return 0;
		}
	}
	cout << -1;

	return 0;
}

#include<iostream>
using namespace std;

int main(){
    int p,y;
    cin>>p>>y;

    int ans=-1;

    for(int i=y;i>p;i--){
        bool check=0;
        for(int j=2;j<=p && j*j<=y;j++)
            if(i%j==0){
                check=true;
                break;
            }
        if(!check){
            ans=i;
            break;
        }
    }

    cout<<ans<<endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long

#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define clr(x)       memset(x,0,sizeof(x))
#define cln(x)       memset(x,-1,sizeof(x))
#define read()       freopen("in.txt","r",stdin)
#define write()      freopen("out.txt","w",stdout)

#define pf2(x,y)    printf("%lld %lld",x,y)
#define pf1(x) printf("%lld",x)
#define sc1(x) scanf("%lld",&x)
#define sc2(x,y)    scanf("%lld %lld",&x,&y)
#define nl printf("\n")
#define mod 1000000007
vector<ll>v;
queue<ll>q;
priority_queue<ll,vector<ll>,greater<ll> >pq;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

int main()
{
   ll p,y,pp;
   //cout<<sqrt(1000000000)<<endl;
   while(cin>>pp>>y)
   {
       ll r=sqrt(y);
       r=max(r,(ll)33000);
       p=min(r,pp);
       if(y%2==0)
         y-=1;
         ll  ck=0,ck1=0;
       for(ll i=y;i>=pp;i-=2)
       {
           ll x=i;
           ck=0;
           for(ll j=3;j<=p;j+=2)
           {
               if(x%j==0)
                 ck=1;
           }
           if(ck==0){
            cout<<x<<endl;
            ck1=1;
            break;
           }
       }
       if(ck1==0)
        cout<<-1<<endl;
   }
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100005;
int n,m;
ll p,y;
int main(){
	int i,j;
	cin>>p>>y;
	for(ll k=y;k>p;k--){
		bool f=1;
		for(ll kk=2;kk<=p&&kk*kk<=y;kk++)
			if(k%kk==0) f=0;
		if(f){
			cout<<k;
			return 0;
		}
	}
	cout<<-1;
	return 0;
}

#include <iostream>
#include <cstdio>

using namespace std;
int p,y;
int ans;

bool isprime(int x){

	for(int i=2;i*i<=x&&i<=p
	;i++){
		if(x%i==0)return 0;
	}
	return 1;

}

int main() {
	cin>>p>>y;
	for(int i=y;i>p;i--){
		if(isprime(i)){
	 		cout<<i;
	 		return 0;
	    }
	}

	cout<<-1;

	return 0;
}

#include <iostream>

using namespace std;
int a;
/*bool prim(int x)
{
    int d;
    if(x==1) return 0;
    if(x%2==0&&x!=2) return 0;
    for(d=3; d*d<=x; d+=2)
        if(x%d==0) return 0;
    return 1;
}*/
bool verif (int val)
{
    int i;
    for(i=2;i*i<=val && i<=a;++i)
        if(!(val%i))
            return false;
    return true;
}
int main()
{
    int b,i,rez=-1,ca=a;
    cin>>a>>b;
    if(b%2==0)
        --b;
    for(i=b;i>a;--i)
    {
        if(verif(i))
        {
            rez=i;
            break;
        }
    }
    cout<<rez;
    return 0;
}

#include <iostream>
using namespace std;
int p,y;

bool isOk(int x){
  for (int i=2;i*i<=x && i<=p;i++){
    if (x%i==0){
        return false;
    }
  }
  return true;
}

int main()
{
  int i;
  cin>>p>>y;
  if (p>=y){
    cout<<-1<<endl;
    return 0;
  }
  for (i=y;i>p;i--){
    if (isOk(i)==true){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int main(){
/*
    int p, y;
    cin >> p >> y;
    int flag = 0;
    if (y%2 == 0)
        y--;

    for(int i = y; i > p; i-=2) {
        flag = 0;
        for(int j = 3; j <= p; j+=2) {
               if(i%j == 0) {
                flag = 1;
                break;
                }
            }
        if(flag == 0) {
            cout << i;
            return 0;
        }
    }
 */
int p, y;
cin >> p >> y;
//p = 28788;
//y = 9441930666;

vector<bool> arr(y + 1, 1);

int flag = 0;

if(p < 3)
    goto a;

    if (y%2 == 0)
        y--;

    for(int i = y; i > p; i-=2) {
        flag = 0;
        for(int j = 3; j <= p && j*j <= y; j+=2) {
               if(i%j == 0) {
                flag = 1;
                break;
                }
            }
        if(flag == 0) {
            cout << i;
            return 0;
        }
    }
cout << -1;
return 0;

a:
for (int i = 2; i <= p && i*i <= y; i++)
    if (arr[i] ==  1)
        for (int j = i*i; j <= y; j += i)
            arr[j] = 0;

for (int i = y; i > p; i--)
    if (arr[i] == 1) {
        cout << i;
        return 0;
    }

cout << -1;
return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int main(){
/*
    int p, y;
    cin >> p >> y;
    int flag = 0;
    if (y%2 == 0)
        y--;

    for(int i = y; i > p; i-=2) {
        flag = 0;
        for(int j = 3; j <= p; j+=2) {
               if(i%j == 0) {
                flag = 1;
                break;
                }
            }
        if(flag == 0) {
            cout << i;
            return 0;
        }
    }
 */
int p, y;
cin >> p >> y;
//p = 28788;
//y = 9441930666;

vector<bool> arr(y + 1, 1);

int flag = 0;

if(p < 9)
    goto a;

    if (y%2 == 0)
        y--;

    for(int i = y; i > p; i-=2) {
        flag = 0;
        for(int j = 3; j <= p && j*j <= y; j+=2) {
               if(i%j == 0) {
                flag = 1;
                break;
                }
            }
        if(flag == 0) {
            cout << i;
            return 0;
        }
    }
cout << -1;
return 0;

a:
for (int i = 2; i <= p && i*i <= y; i++)
    if (arr[i] ==  1)
        for (int j = i*i; j <= y; j += i)
            arr[j] = 0;

for (int i = y; i > p; i--)
    if (arr[i] == 1) {
        cout << i;
        return 0;
    }

cout << -1;
return 0;
}

#include <iostream>

using namespace std;

int check(int n, int p) {
    for(int i=2; i*i<=n&&i<=p; i++)
        if(n%i==0) return i;

    return n;
}

int main()
{
    int p,y;
    cin >> p >> y;

    for(int i=y; i>p; i--){
    //cout << check(i, p) << endl;
    if(check(i, p)>p) {cout << i << endl; return 0;}
    }

    cout << -1 << endl;

    return 0;
}

#include <iostream>

using namespace std;

int p, y;

int main() {
	cin >> p >> y;
	for (; y >= 2; y--) {
		if (y <= p) {
			cout << -1 << endl;
			break;
		}
		bool flag = true;
		for (int i = 2; i * i <= y && i <= p; i++)
			if (y % i == 0) {
				flag = false;
				break;
			}
		if (flag){
			cout << y << endl;
			break;
		}
	}
	return 0;
}

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define sp << " "
#define sps << " " <<
#define lnl << endl <<
#define ln << endl
#define vi vector<int>
#define vc vector<char>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vvll vector<vector<ll>>
#define vii vector<pair<int,int>>
#define vcc vector<pair<char,char>>
#define vic vector<pair<int,char>>
#define pb push_back
#define ppb pop_back
#define forin for(int i = 0; i < n; ++i)
#define forim for(int i = 0; i < m; ++i)
#define forik for(int i = 0; i < k; ++i)
typedef long long ll;
typedef double llf;

using namespace std;

void bubble(vi &a, int n)
{
	int s;
	for (int i = 0; i < n - 1; ++i)
		for (int j = i + 1; j < n; ++j)
			if (a[i] < a[j])
			{
				s = a[i];
				a[i] = a[j];
				a[j] = s;
			}
	return;
}
void choises(int a[], int n)
{
	int s, mm;
	for (int i = 0; i < n - 1; ++i)
	{
		mm = i;
		for (int j = i; j < n; ++j)
			if (a[j] < a[mm])
				mm = j;
		s = a[mm];
		a[mm] = a[i];
		a[i] = s;
	}
	return;
}
void insertion(int a[], int n)
{
	for (int i = 1; i < n; ++i)
		for (int j = 0; j < i; ++j)
			if (a[j] > a[i])
			{
				int s = a[i];
				for (int k = i; k > j; --k)
					a[k] = a[k - 1];
				a[j] = s;
			}
	return;
}
void gnome(int a[], int n)
{
	int i = 1;
	while (i != n)
	{
		if (i == 0)
			++i;
		if (a[i] >= a[i - 1])
			++i;
		else
		{
			int s = a[i];
			a[i] = a[i - 1];
			a[i - 1] = s;
			--i;
		}
	}
	return;
}
void quick(int a[], int l, int r)
{
	int p;
	int left = l;
	int right = r;
	p = a[l];
	while (l < r)
	{
		while (a[r] >= p && l < r)
			r--;
		if (l != r)
		{
			a[l] = a[r];
			l++;
		}
		while (a[l] <= p && l < r)
			l++;
		if (l != r)
		{
			a[r] = a[l];
			r--;
		}
	}
	a[l] = p;
	p = l;
	l = left;
	r = right;
	if (l < p)
		quick(a, l, p - 1);
	if (r > p)
		quick(a, p + 1, r);
}
ll nod(ll a, ll b)
{
	while (a != 0 && b != 0)
		if (a > b)
			a %= b;
		else
			b %= a;
	return a + b;
}
int main()
{
	int p, y, mm = -1;
	cin >> p >> y;
	bool f;

	for (; y > p; y--)
	{
		f = true;
		for (int j = 2; j <= p && j*j <= y; ++j)
			if (y%j == 0)
				f = false;
		if (f)
		{
			cout << y;
			return 0;
		}
	}
	cout << -1;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll int p;
int prime(long long int n)
{
   ll int vv=sqrt(n)+1;
   int vl=min(p,vv);

    if (n%2 == 0){
   //         cout<<"r";
            return 0;}
 //   cout<<n<<'f'<<endl;;

    for (ll int i=3; i<=vl; i=i+1)
    {if (n%i == 0)
        {
      //      cout<<i<<endl;
            return 0;}

    }return 1;
}
int main()
{
    ll int y;int f=0;
    cin>>p>>y;
    for(int h=y;h>max(y-300,p);h--)
    {
       // cout<<h<<' '<<prime(h)<<endl;
        if(prime(h))
        {
            f=1;
           cout<<h<<endl;
           break;
        }
    }
    if(f==0)
        cout<<-1<<endl;
}

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <algorithm>
#include <iostream>
#include <ctype.h>
#include <set>
#include <map>
#include <vector>
#include <stack>
using namespace std;
typedef long long lint;

lint p,y;

bool isSushu(lint num){
    for(lint i = 2; i <= sqrt(num) && i <= p; ++i){
        if(num % i == 0){
            return false;
        }
    }
    return true;
}

int main(){
    scanf("%I64d%I64d",&p,&y); lint ans = -1;
    for(lint i = y; i > p; --i){
        if(i % 2 != 0 && isSushu(i)){
            ans = i; break;
        }
    }
    printf("%I64d\n",ans);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int p,y,i,j,x,counter=0;
    scanf("%lld%lld",&p,&y);
    for(i=y;i>p;i--)
    {
         x=sqrt(i)+1;
        for(j=2;j<=min(x,p);j++)
        {
            if(i%j==0)
            {
                counter=1;
                break;
            }

        }
         if(counter==0)
            {
                cout << i << endl;
                return 0;
            }
            counter=0;
    }
    cout << "-1" << endl;
}

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<sstream>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
typedef long long ll;
using namespace std;

bool is_Prime( int num )
{
    //�����ж�һ�����Ƿ�Ϊ����

    //������С�����⴦��
    if(num ==2|| num==3 )
        return 1 ;
    //����6�ı��������һ����������
    if(num %6!= 1&&num %6!= 5)
        return 0 ;
    int tmp =sqrt( num);
    //��6�ı��������Ҳ���ܲ�������
    for(int i= 5; i <=tmp; i+=6 )
        if(num %i== 0||num %(i+ 2)==0 )
            return 0 ;
    //�ų����У�ʣ���������
    return 1 ;
}

int main()
{
    int p,y;
    cin>>p>>y;
    if(p==y) {
        cout<<-1;    //�ܿ�һ����һ��
        return 0;
    }

    for(int i=y; i>p; i--) { //��Ч���䣨y��p��������

        if(i%2==0) continue;//��֦ ��һ����
        if(is_Prime(i))  {
            cout<<i;    //����һ����������
            return 0;
        }
        int ok=1;
        for(int j=3; j<=p; j++) { //�ڲ�ѭ��
            if(!is_Prime(j)) continue;//��֦ �����ɱ�֮��С����������ɣ�����Ҫ�ڽ����ж�
            if(i%j==0)  {
                ok=0;
                break;
            }

        }

        if(ok) {
            cout<<i;
            return 0;
        }

    }
    cout<<-1;
    return 0;

}

#include <cstdio>
#include <iostream>
#include <cstring>
#include <set>
using namespace std;
typedef long long ll;
int p,y;
int prime(int n){
	int i;
	for(int i=2;i*i<=n&&i<=p;i++){
		if(n%i==0){
			return 0;
		}
	}
	return 1;
}
int main()
{
	cin>>p>>y;
	for(int i=y;i>p;--i){
		if(prime(i)){
			cout<<i<<endl;
			return 0;
		}
	}
	puts("-1");
	return 0;
}

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define readl(a) scanf("%lld", &a)
#define reads(a) scanf("%s", a)
#define p push_back
#define lowbit(n) n & (-n)
#define mem(a) memset(a, 0, sizeof(a));
#define Buff ios::sync_with_stdio(false)
#define sqr(x) x*x
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int>PII;
const int INF = 1e9 + 7;
const double eps = 1e-6;
const int MAXN = 1e6+7;
int p, y;
bool chek(int x)
{
    if(x == 2)  return 1;
    for(int i = 2; i <= p && i * i <= x; i++)
        if(x % i == 0)
            return 0;
    return 1;
}
int main()
{
    scanf("%d %d", &p, &y);
    for(int i = y; i > p; i--)
        if(chek(i))
        {
            printf("%d\n", i);
            return 0;
        }
    printf("-1");
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include<map>
#include<math.h>
#include <bits/stdc++.h>

using namespace std;

long long int fact(long long int n)
{
    for (long long int i=2;i<=sqrt(n);i++ )
    {
        if (n%i==0)
        {
            return i;
        }
    }
    return n;
}

int main()
{
    long long int p,y;
    cin>>p>>y;
    long long int branch=y;
    while (branch>p)
    {
        long long int div=fact(branch);
        if (div>p)
        {
            cout<<branch<<endl;
            break;
        }
        else
        {
            branch--;
        }
    }
    if (branch==p)
    {
        cout<<-1<<endl;
    }
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
using namespace std;
typedef long long ll;
const int maxn = 1e9 + 10;
const int INF = 0x3f3f3f3f;

int main() {
	ios::sync_with_stdio(false);
	int n, m;
	while (cin >> n >> m) {
		int flag = 0;
		for (int i = m; i >= n; i--) {
			int ans = 0;
			for (int j = 2; j <= 100000 && j <= n; j++) {
				if (i % j == 0) {
					ans++;
				}
			}
			if (ans == 0) {
				flag = 1;
				cout << i << endl;
				break;
			}
		}
		if (!flag) {
			cout << "-1" << endl;
		}
	}
	return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int p, y;
    cin >> p;
    cin >> y;
    for(int i=y; i>p; i--)
    {
        int flag =1;
        for(int j =2; j<=p && j*j <=i; j++)
        {
            if(i % j ==0)
            {
                flag =0;
                break;
            }
        }
        if(flag)
        {
            cout << i <<endl;
            return 0;
        }
    }
    cout << -1<<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
    long long p,n;
    cin>>p>>n;
    if(p==2&&n==2|| p==3&&n==3){cout<<-1<<endl;return 0;}
        int y=n;
    for( int i=2;i<=p&&i<=sqrt(n);i++){
                     if(y<=p){cout<<-1<<endl;return 0;}
        if(y%i==0){y--;i=1;}
    }
    cout<<y<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int p,y,i;
int judge(int n)
{
for (int i=2;i*i<=n&&i<=p;i++) if (n%i==0) return 0;
return 1;
}
int main()
{
cin>>p>>y;
for (i=y;i>p;--i) if (judge(i)) return printf("%d",i),0;
puts("-1");
}

/*
Problem Source:

Editorial/Logic/Ideas Sources:
1)
*/

/*
Problem Description:

*/

#include <stdio.h>
#include <math.h>
#include <string.h>

#define INT_MAX				 99999999
#define INT_MIN				-99999999
#define SUCCESS				0
#define MAX_DIM				20001

int input[MAX_DIM];
int p, y;
int max_scr;

static void test_wrapper()
{
	int test_cases, T;
	int i, j;
	int y_root, rem;
	int factor_found;
	int ans;
	int p_min;

#ifdef WINDOWS_TEST
	/* Read number of test cases */
	scanf("%d", &T);
	for(test_cases = 1; test_cases <= T; test_cases++)
#endif
	{
		/* Read Inputs */
		scanf("%d %d", &p, &y);

		//find sqrt
		y_root = (int)sqrt((float)y) + 1;

		ans = -1;
		if(p == 2)
		{
			if(y != 2)
			{
				rem = y % 2;
				if(rem == 0)
				{
					ans = y - 1;
				}
				else
				{
					ans = y;
				}
			}
		}
		else
		{
			//find min
			p_min = p < y_root ? p : y_root;

			//make odd
			if((y % 2) == 0)
			{
				y = y - 1;
			}
			//subtract by 2 to avoid div by 2
			for(i = y; i > p; i-=2)
			{
				factor_found = 0;
				//start from 3
				for(j = 3; j <= p_min; j++)
				{
					rem = i % j;
					if(rem == 0)
					{
						factor_found = 1;
						break;
					}
				}
				if(factor_found == 0)
				{
					ans = i;
					break;
				}
			}
		}

		printf("%d\n", ans);
	}
}

int main()
{
	/* test wrapper function */
	test_wrapper();

	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

ll p,y,fl = 0;
bool lol(ll x){
    for(ll i = 2; i <= p && i <= x / i; i ++){
        if (x % i == 0) return false;
    }
    return true;
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> p >> y;
    for (ll i = y; i > p; i--){
        if (lol(i) == true){
            cout << i;
            fl = 1;
            break;
        }
    }
    if (fl == 0) cout << -1;
}

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

ll p,y,fl = 0;
bool lol(ll x){
    for(ll i = 2; i <= p && i*i <= x; i ++){
        if (x % i == 0) return false;
    }
    return true;
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> p >> y;
    for (ll i = y; i > p; i--){
        if (lol(i) == true){
            cout << i;
            fl = 1;
            break;
        }
    }
    if (fl == 0) cout << -1;
}

#include<bits/stdc++.h>
#define MAXN 50000050
using namespace std;
int p,y;
int main()
{
	scanf("%d%d",&p,&y);
	for(;y>=2;y--)
	{
		if(y<=p){
			printf("%d\n",-1);
			break;
		}
		bool ok=1;
		for(register int i=2;i*i<=y&&i<=p;i++)//仅用<=sqrt(y）的数就可证明它是质数肯定不能被后面的<=p的数整除
		if(y%i==0){ok=false;break;
		}
		if(ok){
			printf("%d\n",y);break;
		}
	}
	return 0;
}

#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <climits>
#include <functional>

using namespace std;

#define ERROR_ID		0

#define PROCESS_ERROR(Condition)    \
{                                   \
		if (!(Condition))	        \
		{                           \
			goto Exit0;             \
		}                           \
}

typedef unsigned char			BYTE;
typedef int						BOOL;
typedef unsigned long			DWORD;
typedef long long				LLONG;

inline int read() {
	int ret = 0, f = 1;
	char ch = getchar();
	while (ch<'0' || ch>'9') {
		if (ch == '-') f = -f;
		ch = getchar();
	}
	while (ch >= '0'&&ch <= '9') ret = ret * 10 + ch - '0', ch = getchar();
	return ret * f;
}//快读优化

BOOL Prime(int nNumber, int nNumberP);

int main(int argc, char* argv[])
{
	int			nNumberP;
	int			nNumberY;

	cin >> nNumberP >> nNumberY;

	for (int i = nNumberY; i > nNumberP; i--)
	{
		if (Prime(i, nNumberP))
		{
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;
	return 0;
}

BOOL Prime(int nNumber, int	nNumberP)
{
	for (int i = 2; i <= sqrt(nNumber) && i <= nNumberP; i++)
	{
		if (nNumber % i == 0)
		{
			return 0;
		}
	}
	return 1;
}

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define next Next
int n,m;
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
bool pd(int x)
{
	for(int i=2;i*i<=x&&i<=n;i++)
		if(x%i==0)return 0;
	return 1;
}
signed main()
{
	n=read();m=read();
	for(int i=m;i>n;i--)
		if(pd(i))
		{
			cout<<i;
			return 0;
		}
	cout<<-1;
}

#include<cstdio>
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=m;i>=2;i--)
	{
		if(i<=n)
		{
			printf("-1");
			return 0;
		}
		bool flag=1;
		for(int j=2;j<=n&&j*j<=i;j++)
			if(!(i%j))
			{
				flag=0;
				break;
			}
		if(flag)
		{
			printf("%d",i);
			return 0;
		}
	}
}

#include<bits/stdc++.h>
using namespace std;
#define sci(n)               scanf("%d",&n)
#define scl(n)               scanf("%lld",&n)
#define scd(n)               scanf("%lf",&n)
#define FOR(i,n)             for(ll i=1;i<=n;i++)
#define LOOP(i,n)            for(ll i=0;i<n;i++)
#define loop(a,b)            for(ll i=a;i<=b;i++)
#define ll long long
#define pb push_back
//#define mp make_pair
bool mp[1000009];
int main()
{
    vector<ll>prime;
    ll n=1000005;
    //cout << sqrt(1000000010) << endl;
    for(ll i=2;i<=n;i++)
    {
        if(mp[i]==0)
        {
            //mp[i]=1;
            prime.pb(i);
           // cout << i << endl;
            for(ll j=i;j<=n;j=j+i)
            {
                mp[j]=1;
            }
        }
    }
    ll p,y;
    scl(p);
    scl(y);
    ll x=sqrt(y);
    x=min(x,p);
    ll flag=0;
    for(ll i=y;i>p;i--)
    {
        flag=0;
        for(ll j=0;j<=prime.size();j++)
        {
            if(prime[j]>x)
            {
                break;
            }
            if(i%prime[j]==0)
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
        {
            cout << i << endl;
            break;
        }
    }
    if(flag==1 || y==p)
    {
        cout << "-1" << endl;
    }
}

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
long long x,y;
bool primecheck(long long x_primecheck)
{
	if(x_primecheck<2||(x_primecheck>2&&x_primecheck%2==0)) return 0;
	for(long long i_primecheck=3;i_primecheck*i_primecheck<=x_primecheck&&i_primecheck<=x;i_primecheck+=2)
		if(x_primecheck%i_primecheck==0)
			return 0;
	return 1;
}
int main()
{
	cin>>x>>y;
	for(int i=y;i>x;i--)
	{
		if(primecheck(i))
		{
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<"-1"<<endl;
	return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 450;
const int inf = 0x3f3f3f3f;
int p,y;
int prime(int x)
{
    for(int i = 2;i*i<=x&&i<=p;i++){
        if(x%i==0) return 0;
    }
    return 1;
}
int main()
{
    scanf("%d%d",&p,&y);
    for(int i = y;i>p;i--){
        if(prime(i)){
            printf("%d",i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
	long long z,x,d=0,s,a;
	cin>>z>>x;
	a=x/2;
	for(long long q=x;q>=a;q--)
	{
		d=0;
		for(long long w=2;w*w<=q;w++)
		{
			if(q%w==0)
			{
				d=1;
				break;
			}
			else
			{
				d=2;
			}
		}
		if(d==1)continue;
		else if(d==2)
		{
			s=q;
			break;
		}
		else if(q==a)
		{
			d=3;
		}
	}
	if(d==2)
	{
		cout<<s<<endl;
	}
	else if(d==3)
	{
		cout<<-1<<endl;
	}
}

#include <bits/stdc++.h>
using namespace std;

bool prime(int x){
    if(x < 2) return false;
    if(x == 2 || x == 3) return true;
    if(x%2 == 0 || x%3 == 0) return false;
    for(int k = 3; k * k <= x + 17; k += 2)
        if(x%k == 0) return false;
    return true;
}

int main(){
    //ios::sync_with_stdio(0);
    //cin.tie(0);

    int p,y; cin >> p >> y;

    for(int k = y; k > p; --k){
        if(prime(k)){
            cout << k << endl;
            exit(0);
        }
    }
    puts("-1");

    return 0;
}

#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <iomanip>
#include <vector>
#define fl(n) for (int i=0; i<n; i++)
#define fl1(n) for (int i=1; i<=n; i++)
typedef long long ll;
using namespace std;
int main() {
    ll p,y;
    cin >> p >> y;
    map<ll,ll> m;
    for (ll i=y; i>p; i--) {
        bool flag=0;
        if (y%2==0) continue;
        for (ll j=2; j<=p; j++) {
            if (i%j==0) {
                flag=1;
                break;
            }
        }
        if (flag) continue;
        cout << i;
        return 0;
    }
    cout << -1;
    return 0;
}

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define N1 10000005
vector<bool>v(N1,true);
vector<ll>prime;
void sieve(ll N, ll y,ll p )
{
    for(ll i=2; i<=p; i++)
    {
        for(ll j=2; j*i<=N; j++)
        {
            v[j*i]=false;
        }
    }
    for(ll i=2; i<=y; i++)
    {
        if(v[i])
        {
            prime.push_back(i);
        }
    }
}
int main()
{
    ll n=0,m=0;
    ll p,y;
    cin>>p>>y;
    if(p==y)
    {
        cout<<-1<<endl;
        return 0;
    }
    n=floor(((double)y/p))*p;
    sieve(n,y,p);
    if(prime.size())
    {
        cout<<prime[prime.size()-1]<<endl;

    }
    else
        cout<<-1<<endl;
}

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include <cmath>
#include <ctype.h>
#include <iomanip>
#include <set>
#include <bitset>

using namespace std;

int main() {
	long long int b , y;
	cin >> b >> y;
	int n = sqrt(y);
	vector <int> vec;
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = 0;

	for (long long i = 2; i*i <= n; ++i) {
		if (isPrime[i]) {
			for (int j = i * 2; j <= n; j += i)
				isPrime[j] = 0;
		}
	}

	int cnt = 0;

	for (int i = 0; i < (int)isPrime.size(); ++i)
	if (isPrime[i])
		vec.push_back(i);
	if (y % 2 == 0)y--;
	for (int i = y; i > vec[(vec.size() - 1)]; i-=2){
		bool t = 1;
		for (int j = 0; j < vec.size(); j++)if (i%vec[j] == 0){
			t = 0; break;
		}
		if (t == 1){
			cout << i << endl;
			return 0;
		}

	}

	cout << "-1" << endl;
	return 0;
}

#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

int main()
{

	int p, y;
	scanf("%d%d", &p, &y);
	int max = p;// > 500 ? 500 : p;

	while (y > 1)
	{
		bool isSuccess = true;
		int n = 2;
		while (n * n <= y)
		{
			if (y % n == 0)
			{
				isSuccess = false;
				break;
			}
			n++;
			if (n > max)
				break;
		}

		if (isSuccess)
		{
			printf("%d\n", y);
			return 0;
		}
		else
			y--;
	}

	printf("-1\n");

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll p,y; cin >> p >> y;
    if(y % 2 == 0){
        if(y -1 <= p){
            cout << -1;
        }
        else{
            cout << y-1;
        }
    }
    else{
        cout << y;
    }

}

#include<bits/stdc++.h>
using namespace std;
#define read FILE *fp;\
fp=freopen("testcase.txt","r",stdin);
#define ll long long
#define ull unsigned long long
#define sf(n) scanf("%I64d",&n)
#define pf(n) printf("%I64d\n",n)
#define loop for(long long i=0;i<n;i++)
#define lp(b,n) for(long long i=b;i<=n;i++)
#define pb(n) push_back(n)
#define srt(v) sort(v.begin(),v.end())
#define rvs(v) sort(v.begin(), v.end(), greater<long long>());
#define F first
#define S second
#define mp(a,b) make_pair(a,b);
#define fio ios::sync_with_stdio(false); cin.tie(),cout.tie();
#define l 100000
ll mark[5010];
long long a[1000000],prime[100000];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(),cout.tie();
    ll e;
    for(ll i=3; i*i<=l; i+=2)
        if(a[i]==0)
            for(ll j=i*i; j<=l; j=j+(i*2))
                a[j]=1;
    prime[0]=2;
    for(ll i=3,j=1; i<=l; i+=2)
        if(a[i]==0)
        {
            prime[j++]=i;
            e=j;
        }
        ll p,n;
        cin>>p>>n;
        for(ll i=n;i>p;i--)
        {
            ll z=0,x=0,b=0;
            for(ll j=2;j*j<=i;j++)
            {
                if(i%j==0)
                {
                    z=1;
                    break;
                }
            }
            if(z==0)
            {
                cout<<i<<endl;
                return 0;
            }
        }
        cout<<-1<<endl;

}

#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <set>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <tuple>
#include <map>
#include <stdio.h>
#include <stdlib.h>
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

ll p,y,ans=0;
int main()
{
  	scanf("%lld%lld",&p,&y);

  	if(y%2==0)y--;
  	for(ll i=y; i>p; i-=2){
  		bool a=false;
  		for (ll j = 2; j*i <= y && j <= p ; ++j)
  		{
  			if(i%j==0){a=true;break;}
  		}
  		if(!a){printf("%lld",i);return 0;}
  	}

  	printf("-1");
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll p, y;
ll gcd(ll a, ll b){
	return b ? gcd(b, a%b) : a;
}
int main(){
	scanf("%lld%lld", &p, &y);
	ll l = 1;
	for (int i = 2; i <= p; i++){
		ll g = gcd(l, i);
		l = l / g*i;
		if (l > y)return !printf("-1\n");
	}
	ll t = (y + 1) / l;
	printf("%lld\n", t*l - 1);
	return 0;
}

  #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef long double ld;
    int setbit(int n, int i, int v)
    {
            return ((v) ? (n | (1 << i)) : (n&~(1 << i)));
    }
    ll gcd(int i, int j)
    {
            if (j == 0)
                    return i;
            return gcd(j, i%j);
    }
    bool chk(int n, int i)
    {
            if ((n >> i) & 1 == 1)
                    return 1;
            return 0;
    }

    ll max(ll a, ll b)
    {
            return a >= b ? a : b;
    }
    string tostring1(ll n)
    {
            string res = "";
            while (n)
            {
                    res += ((n % 10) + '0');
                    n /= 10;

            }
            reverse(res.begin(), res.end());
            return res;
    }
    bool T(pair<int, int>p1, pair<int, int>p2)
    {
            return (p2.second - p1.first >= p2.second - p2.first);
    }
    ll todec(string s)
    {
            ll res = 0; ll cnt = 0;
            for (int i = s.length() - 1; i >= 0; i--)
            {
                    res += (s[i] - '0')*pow(10, cnt);
                    cnt++;
            }
            return res;
    }

    int prime(ll n)
    {
        for(int i=2;i<=sqrt(n);i++)
        {
            if(n%i==0)
                return 0;
        }
        return 1;
    }
    int main()
    {
        ll p,y;
        cin>>p>>y;
        for(int i=y;i>p;i--){
            if(prime(i))
            {
                cout<<i<<endl;
                exit(0);
            }
        }
        cout<<-1<<endl;

            return 0;
    }

#include<bits/stdc++.h>
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define sz size()
#define din 9111111
using namespace std;
const int mnx = 1e6 + 6;
const int mod = 1e9 + 7;

ll x, y, t, cnt;

int binpow(int a, int n){
if (n == 0)
return 1;
if(n % 2 == 1)
return binpow (a, n-1) * a;
else {
int b = binpow (a, n/2);
return b * b;
}
}

int main(){

cin>>x>>y;

for(int i=y; i>x; i--){

for(int j=2; binpow(j, 2)<=i && j<=x; ++j){
if(i%j == 0) cnt = 0;
else cnt = 1;
}

if(cnt != 0){ cout<<i<<endl; return 0; }

}

cout<<"-1";

return 0;

}

#include <bits/stdc++.h>

using namespace std;
long long  N, M;
bool Ok;
int main()
{
    scanf("%lld %lld", &N, &M);
    if(M % 2 == 0) M--;
    while(M > N) {
        Ok = 1;
        for(int d = 3; d * d <= M; d += 2) if(M % d == 0) Ok = 0;
        if(Ok) {
            printf("%lld", M);
            return 0;
        }
        M -= 2;
    }
    printf("-1");
    return 0;
}

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define N 10000005
vector<bool>v(N,true);
vector<int>prime;
void sieve()
{
    for(int i=2; i*i<=N; i++)
    {
        for(int j=i*2; j<=N; j+=i)
        {
            v[j]=false;
        }
    }
    for(int i=2; i<=N; i++)
    {
        if(v[i])
        {
            prime.push_back(i);
        }
    }
}
int main()
{
    int n=0,m=0,c=0;
    sieve();
    int p,y;
    cin>>p>>y;
    for(int i=2; i<=p; i++)
    {
        if(y%i==0)
        {
            c++;
        }
    }
    if(c)
    {
        for(int i=0; i<prime.size(); i++)
        {
            if(prime[i]>p && prime[i]<=y)
            {
                n=prime[i];
            }
            if(n>m)
                m=n;
        }
        if(m)
        {
            cout<<m<<endl;

        }
        else
            cout<<-1<<endl;
    }
    else
        cout<<y<<endl;
}

#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define len(a) sizeof(a)/sizeof(*a)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define pb push_back

typedef long long ll;
inline ll gcd(ll a, ll b) {ll r; while (b != 0) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}

bool isPrime(int n){
    if(n < 2){
        return false;
    }
    for(int i = sqrt(n);i >= 2;i--){
        if(n % i == 0)
            return false;
    }
    return true;
}

bool dmkien(int x, int p){
    for(int i = p; i <= sqrt(x);i++){
        if(isPrime(i)){
        int k = x;
        while(!(k % i)){
            k /= i;
        }
        if(k == 1){
            return true;
        }
        }

    }
    return false;
}

void solve(){
    int p,y;
    cin >> p >> y;
    if(p == 2){
        if(y&1){
            cout << y << endl;
        }else{
            cout << y - 1 << endl;
        }
        return;
    }
    int x = 1;
    for (int i = y;i > p;i--){
        if( (i&1) && isPrime(i)){
            x = i;
            break;
        }
    }
    int k = 1;
    for(int i = y; i > p;i--){
        if(dmkien(i,p)){
            k = i;
            break;
        }
    }

    int m = MAX(x , k);
    if(m!=1){
        cout << m << endl;
        return;
    }

    cout << -1 << endl;

}

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}

#include <iostream>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <set>
using namespace std;

int n, k, a, ans = -1;
set <int> s;

int main()
{
	cin >> n >> k;
	int i = 0;
	for (int a = k; a >= 2; a--)
	{
		if (i > 100000)break;
		int b;
		for (b = 2; b <= sqrt(a) + 1; b++)
		{
			if (a % b == 0)break;
		}
		if (b == n + 1)return cout << a, 0;
		i++;
	}

	cout << -1;
}

#include <bits/stdc++.h>

using namespace std;
vector<int> prime;
char sieve[1000000+100];
void primeSieve ( int n )
{
    sieve[0] = sieve[1] = 1;

    prime.push_back(2);
    for ( int i = 4; i <= n; i += 2 ) sieve[i] = 1;

    int sqrtn = sqrt ( n );
    for ( int i = 3; i <= sqrtn; i += 2 )
    {
        if ( sieve[i] == 0 )
        {
            for ( int j = i * i; j <= n; j += 2 * i ) sieve[j] = 1;
        }
    }

    for ( int i = 3; i <= n; i += 2 ) if ( sieve[i] == 0 ) prime.push_back(i);
}

int main()
{
    // freopen("i.txt","w",stdout);
    primeSieve(1000000+10);
    int   n, k ;
    while(cin >> n>> k )
    {
        int flag = 0 ;
        if ( n == 2  )
        {
            if ( k % 2 == 0 )cout << k - 1 << endl;
            else cout << k << endl;
            flag = 1 ;

        }
        else
        {
            int ok = 0 ;
            for(int  j=k; j>=n+1; j--)
            {
                ok = 0 ;
                if(j%2 == 1)
                {
                    int sqrtn = sqrt(j);
                    for( int i = 0 ; ; i ++ )
                    {
                        if ( prime[i]>sqrtn || prime[ i ] > n)
                        {
                            break ;
                        }
                        else
                        {
                            if ( j % prime[i] == 0 )
                            {
                                ok = 1 ;
                                break ;
                            }

                        }

                    }
                    if ( ok == 0 )
                    {
                        printf("%d\n",j);
                        flag = 1 ;
                        break;
                    }
                }
            }
        }
        if ( flag == 0)
            printf("-1\n");
    }

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int p, y;
int res;

bool check (int n)
{
    if (n < 2) return false;
    for (int i = 2; i <= trunc(sqrt(n)); i++)
        if (n % i == 0) return false;
    return true;
}

int main()
{
    cin >> p >> y;
    for (int i = y; i >= p; i--)
    {
        if (check(i))
        {
            cout << i; return 0;
        }
    }
    cout << -1;
}

/*     !ya khoda!     */
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define ld long double

#define pp push
#define po pop()
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()

#define F first
#define S second

#define mkp make_pair
#define pll pair<ll,ll>

#define coutghat(x)      cout<<tolower(x);
#define coutashar(x,d)   cout<<fixed<<setprecision(x)<<(ld)d
#define IOS ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
//#define poow(a,b,M)   b?(poow((a*a)%M,b/2)%M * (b&1?a))%M:1 ;
/*==========================================================================*/
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
//#pragma optimize O3
// 107,109, 211,223, 307, 401,409, 503,509, 601,607, 701,709, 809, 907, 1009
/*==========================================================================*/
const int N=1e5+100 , M=30 , LG=26 , base=2;
const int MOD=1e9+7 , mod=1e9+9;
const ll  INF=1e9   , inf=1e18 ;
ll n,m,p,y , check,ans;
/*==========================================================================*/
int main()
{
	IOS;
	cin>>p>>y;
	n=min((ll)sqrt(y)+1,p);

	for(int i=y ; i>=y-N && i>0 ; i--)
    {
        check=0;
        for(int j=2;j<=n;j++)
            if(i%j==0 || j>=i)
            {
                check=1;
                break;
            }
        if(check==0)
            ans=max(ans,(ll)i);
    }

    for(int i=ans;i<=y;i++)
    {
        for(int j=2;j<=n;j++)
            if(i%j==0 || j>=i)
            {
                check=1;
                break;
            }
        if(check==0)
            ans=max(ans,(ll)i);
    }

    if(ans==0)   return cout<<-1 , 0;
	cout<<ans;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define read freopen("in.c", "r", stdin)
#define write freopen("out.c", "w", stdout)
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define ff first
#define ss second
#define left(x) ((x) + (x) + 1)
#define right(x) ((x) + (x) + 2)
#define pb push_back
#define pp pop_back
#define eps 1e-9
#define mx 100005
#define mmx 100000005
#define mmod 1000000007
#define inf (INT_MAX - 5)
#define cs(p) printf("Case %d:", (p)++)
#define nl puts("")
#define sp printf(" ")
#define out(a) printf("%lld", (ll)(a))

ll in()
{
    ll a;
    scanf("%lld", &a);
    return a;
}

vl primes;
bool check[mx*10];

void sieve()
{
    for(int i = 4; i < mx*10; i += 2)
        check[i] = true;
    primes.pb(2);
    for(ll i = 3; i < mx*10; i += 2)
    {
        if(!check[i])
        {
            primes.pb(i);
            for(ll j = i * i; j < mx*10; j += i + i)
                check[j] = 1;
        }
    }
}

bool isprm(ll n)
{
    if(n <= 1)
        return false;

    if(n <= 3)
        return true;

    for(ll i = 2; i * i <= n; i++)
        if(n%i == 0)
            return false;

    return true;
}

int main()
{
    sieve();
    ll p = in(), y = in();

    int k = lower_bound(all(primes), p) - primes.begin();
    if(k >= primes.size())
        k--;

    ll s = primes[k];

    for(ll i = y; i > p; i--)
    {
        int f = 1;
        for(int j = 0; j <= k; j++)
        {
            if(i % primes[j] == 0)
                f = 0;
        }
        if(f)
        {
            out(i), nl;
            exit(0);
        }
    }

    out(-1), nl;
    return 0;
}

//Bismillahir Rahmanir Rahim

#include<bits/stdc++.h>
#include<iterator>
using namespace std;

#define FI freopen("input.txt","r",stdin)
#define FO freopen("output.txt","w",stdout)

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<LL> VLL;

//**iterate
#define FE(i,x) for(auto i=begin(x);i!=end(x);i++)

//**for loop
#define REP(i,n) for(auto i=0;i<n;i++)
#define REPR(i,n) for(auto i=n;i>0;i--)

#define REPS(i,a,n) for(auto i=a;i<n;i++)
#define REPSR(i,n,a) for(auto i=n;i>a;i--)

//**math constant
#define PI 3.14159265359

//IIconstant
#define siz 1000000000+10
#define mx 5000+10
#define modV 1000000000+7
#define intMax 1000000000000000000

//**Compare

class CMP
{
public:
    bool operator()(pair<int,int> n1,pair<int,int> n2)
    {
        if(n1.second==n2.second)
            return n1.first>n2.first;
        return n1.second>n2.second;
    }
};

bool cmp(ULL a, ULL b)
{
    return a>b;
}

//**Initial codes not needed every time

stack<char> S;
queue<pair<int,int>> Q;
set<int> ST;
//map<LL,LL> MP;
priority_queue<pair<int,int>, vector<pair<int,int>>, CMP > PQ;

vector<char> v;

int dx[8]= {0,0,1,-1,1,1,-1,-1},dy[8]= {1,-1,0,0,1,-1,1,-1};

//** code starts from here

//**Global Variable

//bool visit[mx];

int main()
{
    ios::sync_with_stdio(false);
    //FI;
    //FO;
    //cout<<sqrt(1000000000)*1000<<endl;
    LL p,y;
    cin>>p>>y;
    if(y==2){
        cout<<-1<<endl;
        return 0;
    }
    if(p==2){
        if(y%2==0)y--;
        cout<<y<<endl;
        return 0;
    }
    if(y%2==0)y--;

    //cout<<l<<endl;
    bool fnd;
    for(LL i=y;i>p;i-=2){
        fnd=true;
       // cout<<"i="<<i;
       LL l=sqrt(i)+2;
        for(LL j=3;j<=l;j+=2){
            //cout<<" j="<<j;
            if(i%j==0){
                fnd=false;
                break;
            }
        }
        //cout<<endl;
        if(fnd){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define read freopen("in.c", "r", stdin)
#define write freopen("out.c", "w", stdout)
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define ff first
#define ss second
#define left(x) ((x) + (x) + 1)
#define right(x) ((x) + (x) + 2)
#define pb push_back
#define pp pop_back
#define eps 1e-9
#define mx 100005
#define mmx 100000005
#define mmod 1000000007
#define inf (INT_MAX - 5)
#define cs(p) printf("Case %d:", (p)++)
#define nl puts("")
#define sp printf(" ")
#define out(a) printf("%lld", (ll)(a))

ll in()
{
    ll a;
    scanf("%lld", &a);
    return a;
}

vl primes;
bool check[mx*10];

void sieve()
{
    for(int i = 4; i < mx*10; i += 2)
        check[i] = true;
    primes.pb(2);
    for(ll i = 3; i < mx*10; i += 2)
    {
        if(!check[i])
        {
            primes.pb(i);
            for(ll j = i * i; j < mx*10; j += i + i)
                check[j] = 1;
        }
    }
}

bool isprm(ll n)
{
    if(n <= 1)
        return false;

    if(n <= 3)
        return true;

    for(ll i = 2; i * i <= n; i++)
        if(n%i == 0)
            return false;

    return true;
}

int main()
{
    sieve();
    ll p = in(), y = in();

    int k = lower_bound(all(primes), p) - primes.begin();
    if(k >= primes.size())
        k--;

    ll s = primes[k];

    for(ll i = y; i > p; i--)
    {
        int f = 1;
        for(int j = 2; j <= k; j++)
        {
            if(i % primes[j] == 0)
                f = 0;
        }
        if(f)
        {
            out(i), nl;
            exit(0);
        }
    }

    out(-1), nl;
    return 0;
}

#include<bits/stdc++.h>

#define pb push_back

using namespace std;

const int N = 3e5 + 10;
const int INF = 3e9 + 10;

bool pr(int x)
{
    int st = x;
    for (int i = 2;i * i <= x;++i)
    {
        if (x % i == 0)
            while (x % i == 0) x /= i;
    }
    return x == st;
}

int p, y;

main ()
{
    ios_base::sync_with_stdio(false);
    cin >> p >> y;
    for (int i = y;i > p;--i)
    {
        int sq = sqrt(i);
        if (pr(i))
        {
            cout << i;
            return 0;
        }
        for (int j = 2;j <= sq;++j)
        {
            if (i % j == 0 && j > p)
            {
                cout << i;
                return 0;
            }
        }
    }
    cout << -1;
    return 0;
}

#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define sz(v)				((int)((v).size()))
#define clr(v, d)			memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)

typedef long long         ll;
const ll OO = 1e8;

const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}

#define pb					push_back
#define MP					make_pair
#define P(x)				cout<<#x<<" = { "<<x<<" }\n"
typedef long double   	  ld;
typedef vector<int>       vi;
typedef vector<double>    vd;
typedef vector< vi >      vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;

const ll MAX1 = 100011;
const ll MAX2 = 9999999;
const int MAX3 = 100;

int main()
{
	ll x=-1,z=0,n,a[MAX2]={-1},aa[MAX2]={0};
	ll p,y;

	cin>>p>>y;

	for (ll i = y-1; i >= p; i--)
	{
		z=0;
		for (ll j = 2; j <= 100000; j++)
		{
			if(i%j==0)
			{
				z=2;
				break;

			}

		}
		if(z!=2)
			{
				cout<<i;
				return 0;
			}

	}

	cout<<-1;
return 0;
}

#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define input freopen("input.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define fast_io ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
#define fix cout << fixed << setprecision(15);
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int> ;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int> ;
using vll = vector<ll> ;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const ll basell = 1e18 + 3;
const int mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int nv = 100100;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(ld a, ld b) { return fabs(a-b) < 1e-9; }
//ifstream cin("input.txt");
//ofstream cout("output.txt");
//cout << fixed << setprecision(15);
/*
for(int c : s)
for (int &i : a) cin >> i;
for(int c = 'a'; c <= 'z'; ++c)
vector<vector<ll>> dp(n, vector<ll>(n+2));     // 10 10 10 20 20 20 30 30
low = std::lower_bound (v.begin(), v.end(), 20); //          ^
up = std::upper_bound (v.begin(), v.end(), 20); //                   ^
char 0 = int 48;
char c = cin;
int h = (int)c - 48;
*/

const int SQRT_MAXN = 100000; // корень из максимального значения N
const int S = 10000;
bool nprime[SQRT_MAXN], bl[S];
int primes[SQRT_MAXN], cnt = 0;

int solve() {
    //input;//,output;
    //fix;
    fast_io;
    int p, n;
    cin >> p >> n;
    int nsqrt = (int) sqrt(p + .0);
    if(p<100000){
        nsqrt = p;
    }
    for (int i = 2; i <= nsqrt; ++i)
        if (!nprime[i]) {
            primes[cnt++] = i;
            if (i * 1ll * i <= nsqrt)
                for (int j = i * i; j <= nsqrt; j += i)
                    nprime[j] = true;
        }

    int result = 0;
    for (int k = n / S; k >= 0; --k) {
        memset(bl, 0, sizeof bl);
        int start = k * S;
        for (int i = 0; i < cnt; ++i) {
            int start_idx = (start + primes[i] - 1) / primes[i];
            int j = max(start_idx, 2) * primes[i] - start;
            for (; j < S; j += primes[i]){
                bl[j] = true;
                //cout << start + bl[j] << '\n';
            }
        }
        if (k == 0)
            bl[0] = bl[1] = true;
        int h = 0;
        for (int i = 0; i < S && start + i <= n; ++i) {
            if (!bl[i]) {
                result = start + i;
                h = 1;
            }
        }
        if (h == 1) break;
    }
    if (result == 0 || result <= p) cout << -1;
    else cout << result;
}

int32_t main() {
    solve();
    return 0;
}

/*
2
3 2
1 2 1
2 3 2
3 2
1 2 1
2 3 2
 * */

#include <bits/stdc++.h>
using namespace std;

bool prime(int x){
    if(x < 2) return false;
    if(x == 2 || x == 3) return true;
    if(x%2 == 0 || x%3 == 0) return false;
    for(int k = 3; k * k <= x; k += 2)
        if(x%k == 0) return false;
    return true;
}

int main(){
    //ios::sync_with_stdio(0);
    //cin.tie(0);

    int p,y; cin >> p >> y;

    for(int k = y; k > p; --k){
        if(prime(k)){
            cout << k << endl;
            exit(0);
        }
    }
    puts("-1");

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
void Vile_Grasshoppers_Solution()
{
    int p,y;
    cin>>p>>y;
    for(int i=y;i>=p;i--)
    {
        int flag=1;
        for(int j=2;j*j<=y&&j<=p;j++)
        {
            if(i%j==0)
            {
                flag=0;
                break;
            }
        }
        if(flag) { cout<<i;return;}
    }

    cout<<-1;
}
int main()
{
    Vile_Grasshoppers_Solution();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,p;
    cin>>n>>p;
    while(p>2)
    {
        if(p%2!=0&&p%n!=0)
        {
            cout<<p;
            return 0;
        }
        p--;
    }
    cout<<-1;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
  long long int p,y,i,j,n;
  cin>>p>>y;
  n=sqrt(y);
  map<long long int ,int > m;
  for(i=1;i<=y;i++)
  {
    m[i]=1;
  }
  for(i=2;i<=n;i++)
  {
    if(m[i]==1)
    {
      for(j=2;i*j<=y;j++)
      {
        m.erase(i*j);
      }
    }
  }
  map<long long int ,int > :: iterator itr;
  for(itr=m.end();itr!=m.begin();itr--)
  {
    if(itr->second==1)
    {
      if(itr->first >p)
      {cout<<itr->first<<endl;
        return 0;
      }
      else
      {
        cout<<"-1"<<endl;
        return 0;
      }
    }
  }
  cout<<"-1\n";
}

#include <bits/stdc++.h>
using namespace std;

#define sf1(a)                scanf("%d", &a)
#define sf2(a,b)              scanf("%d %d",&a, &b)
#define sf3(a,b,c)            scanf("%d %d %d", &a, &b, &c)
#define sf4(a,b,c,d)          scanf("%d %d %d %d", &a, &b, &c, &d)

#define sf1ll(a)              scanf("%I64d", &a)
#define sf2ll(a,b)            scanf("%lld %lld", &a, &b)
#define sf3ll(a,b,c)          scanf("%I64d %I64d %I64d", &a, &b, &c)
#define sf4ll(a,b,c,d)        scanf("%I64d %I64d %I64d %I64d", &a, &b, &c, &d)
map <long long , long long > vis ;
int main(){
 long long   k , y , i ;
sf2ll(k,y);
for (int i = y ; i > y-10 ; i--){
        bool flag = false ;
    for (int j = 2;j<=k;j++){
        if (i%j == 0) {flag = true ; break ;}
    }
    if (!flag) {cout << i ; return 0; }
}

cout << -1 ;
}

#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	long long n,p,y;
	cin>>p>>y;
	if(y%2==0)y--;
	for(int i=y;i>p;i-=2){
		int sq=sqrt(i);
		bool flag=false;
		for(int j=2;j<sq and j<=p and j<i;j++){
			if(i%j==0){
				flag=true;
				break;
			}
		}
		if(!flag){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}

#define ll long long
#define MOD 1000000007
#include <bits/stdc++.h>
using namespace std;
bool isprime(ll N){
    for(int i=2;i<sqrt(N);i++)
    {
      if(N%i==0)
      return false;
    }
    return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll p,y,j,k,i;
  cin>>p>>y;
  int flag;
  for(i=y;i>p;i--)
  if(isprime(i)==true)
  break;
  for(j=y;j>=i;j--)
  {
    flag=0;
    for(k=2;k*k<=j;k++)
    {if(j%k==0)
    {flag=1;break;}}
    if(flag==0)
    break;
  }
  if(y==p && y==2)
  flag=1;
  if(flag==0)
  cout<<j;
  else
  cout<<"-1";
  return 0;
}

#include <bits/stdc++.h>
#define task "B."
#define ff(i, a, b) for (int i = a; i <= (int) b; ++i)
#define fd(i, a, b) for (int i = a; i >= (int) b; --i)
#define rep(i, a, b) for (int i = a; i < (int) b; ++i)
#define inf 1e9
#define pb push_back
#define x first
#define y second
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int, int > II;
typedef pair < ll, ll > PLL;
typedef pair < double, int > DI;

const int dd[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int bran, high;

void enter()
{
//    freopen(task"inp", "r", stdin);
//    freopen(task"out", "w", stdout);
    ios_base::sync_with_stdio(false);
    scanf("%d%d", &bran, &high);
}

bool check(int x)
{
    if (x < 2) return false;
    for (int i = 2; i <= (int)sqrt(x); ++i)
        if (x % i == 0) return false;
    return true;
}

void solve()
{
    int d = -1;
    int tg = bran + 1;
    if (tg % 2 == 0) ++tg;
    int res = -1;
    if (tg >= high) tg = -1;
    else
    {
        res = (high / tg * tg);
        if (res % 2 == 0) res -= tg;
    }
    tg = high;
    if (res == -1) printf("-1");
    else
    {
        while (tg >= res)
        {
            if (check(tg)) { d = tg; break; }
            --tg;
        }
        printf("%d", max(res, d));
    }
}

int main()
{
    enter();
    solve();
    return 0;
}

#include <iostream>
using namespace std;
//http://codeforces.com/problemset/problem/937/B

/*int main() {
	//http://codeforces.com/problemset/problem/954/C
	int min, max, n, a, b, x, y;
	y = -1;
	cin >> n;
	cin >> a;
	min = max = a;
	while (n > 1) {
		n--;
		b = a;
		cin >> a;
		if (y != -1) {
			if (abs(a - b) == 1) {
				//One is at the begin, other at the end
				if (a + b % (2 * y) == 1) {
					cout << "NO";
					return 0;
				}
			} //Not col-adjacent
			else if (abs(a - b) != y) {
				cout << "NO";
				return 0;
			}
		}
		else if (abs(a - b) != 1) {
			y = abs(a - b);
			if (y == 0 || (min - 1) / y != (max - 1) / y) {
				cout << "NO";
				return 0;
			}
		}
		if (a < min) min = a;
		if (a > max) max = a;
	}
	if (y == -1) y = 1;
	x = (max - 1) / y + 1;
	cout << "YES\n" << x << " " << y;
}*/
int main() {
	int prime[32000] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
	//Max number prime is around 3500
	int n = 14, i, j, p, y, tmp;
	cin >> p >> y;
	//Generate primes up to sqrt y
	if (p > 9000000000 && y > 9000000000) {
		y = 944192809;
	}
	int mp = sqrt((float)y * 2);
	for (i = 49; ; i+=2) {
		tmp = sqrt((float)i);
		for (j = 0; prime[j] <= tmp; j++)
			if (i % prime[j] == 0)
				break;
		if (prime[j] > tmp) {
			prime[n++] = i;
			if (i > mp) break;
		}
	}
	//From pre-built
	if (p > mp) mp = p;
	if (p > 1 && y % 2 == 0) --y;
	while (y > mp) {
		tmp = sqrt((float)y);
		if (tmp > p) tmp = p;
		for (j = 0; j < n && prime[j] <= tmp; j++)
			if (y % prime[j] == 0)
				break;
		if (prime[j] > tmp) break;
		y -= 2;
	}
	cout << (y > mp ? y : -1);
	//return 0;
}

#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <fstream>
#include <limits.h>
using namespace std;
typedef long long ll;
bool is_prime (ll n)
{
	if (n==2) return true;
	int u = ceil(sqrt((double)n));
	for (int i = 2;i<=u;i++)
	{
		if (n%i==0) return false;
	}
	return true;
}
int main ()
{
	int p,y;
	cin>>p>>y;
	/*ll curp = 2;
	ll ans_t = -1;
	while (curp <= p)
	{
		ll cur = 2;
		ll ans = 1;
		while (true)
		{
			if (is_prime (cur) && cur <= curp)
			{
				ans *= cur;
			}
			cur++;
			if (cur > curp) break;
		}
		if (ans - 1 < y && ans - 1 > p)
		ans_t = ans - 1;
		curp++;
	}
	cout<<ans_t;
	*/
	while (true)
	{
		int cur = ceil(sqrt ((double)y));
		bool valid = true;
		int lim = min(cur,p);
		for (int i = 2;i<=lim;i++)
		{
			if (y % i == 0)
			{
				valid = false;
				break;
			}
		}
		if (valid)
		{
			break;
		}
		y--;
	}
	if (y <= 3)
	cout<<-1;
	else
	cout<<y;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define pp pop_back
#define mp make_pair
#define MOD 1e9+7

int main(){
	ll p,y;
	cin >> p >> y;

	vector<bool>  v(1000000,true);
	vector<int> x;

	for(int i=2;i*i<=1000000;i++){
		x.pb(i);

		if(v[i]){
			for(int j=i+i;j<1000000;j+=i){
				v[j]=false;
			}
		}
	}

	bool f=false;
	int ans=-1;

	while(y > p && f==false){

		bool f1=true;

		for(int i=0;i<x.size() && x[i]<=p;i++){

			if(y%x[i] == 0){
				//cout << y << " " << x[i] << endl;
				f1=false;
				break;
			}

		}
		if(f1){
			ans=y;f=true;
		}

		y--;
	}

	cout << ans << endl;

}

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define inf 9e18
using namespace std;

int fnd(int n){
    for(int i=2;i*i<=n+10;i++){
        if(n%i == 0) return i;
    }
    return n;
}

signed main(){
    int p,y;
    cin >> p >> y;
    int _y = y;
    while(y-- && y>=p){
        if(fnd(y) > p){
            return cout << y << endl,0;
        }
        if(y < _y - 1000) break;
    }
    cout << -1;
}

#include <cstdio>
#include <algorithm>
using namespace std;
#define maxn 1000010
bool flg[maxn];
int p,y;
int main(){//freopen("in.txt","r",stdin);freopen("o1.txt","w",stdout);
	scanf("%d%d",&p,&y);
	if(p>=y){
		printf("-1");return 0;
	}
	int i;
	for(i=3;i<=p;i+=2){
	if(flg[i])continue;
		for(int j=i+i;j<=y;j+=i)
		flg[j]=1;
	}
	if(y%2==0)--y;
	for(i=y;i>1;i-=2)if(!flg[i]){
		printf("%d",i);return 0;
	}
	printf("-1");
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
   int p , y;

   cin>>p>>y;

   int ok=0;

   while(!ok && y>2)
   {
       int aux=0;
       for(int i=2; i <=p && !aux;i++)
          if(y%i!=0)
            aux=1;
       if(aux==0)
         ok=1;
        y--;
   }
  if(ok)
   cout<<y;
   else
    cout<<-1;
}

#include <iostream>
#include <string.h>
using namespace std;

bool prime[100000];

void SieveOfEratosthenes()
{
    memset(prime, true, 100000);

    for (int p=2; p*p<=100000; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p
            for (int i=p*2; i<=100000; i += p)
                prime[i] = false;
        }
    }
}

long int findPrime(long long int p, long long int y){
    SieveOfEratosthenes();
    if(y%2 == 0){
        for(long long int i = (y-1); i>p; i-=2){
            bool flag = false;
            for(long long int j = 3; j*j<=i; j+=2){
                if(prime[j] && i%j == 0){
                    flag = true;
                    break;
                }
            }
            if(flag == false)
                return i;
        }
    }
    else{
        for(long long int i = y; i>p; i-=2){
            bool flag = false;
            for(long long int j = 3; j*j<=i; j+=2){
                if(prime[j] && i%j == 0){
                    flag = true;
                    break;
                }
            }
            if(flag == false)
                return i;
        }
    }
    return -1;
}

int main()
{
    long long int p, y;
    cin>>p>>y;
    cout<<findPrime(p, y);
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
	long long p, y, x;
	bool flag, jk;
	while(cin >> p >> y) {
		x = p + 1;
		flag = false;
		while(x != y) {
			jk = true;
			for(long long P = 2LL; P <= p; P++) {
				if(x % P == 0LL) {
					jk = false;
					break;
				}
			}
			if(jk) {
				cout << x << "\n";
				flag = true;
			}
			if(flag) break;
			x++;
		}
		if(!flag) cout << -1 << "\n";
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define repi_0(st,n) for(i=st;i<n;i++)
#define repi_1(st,n) for(i=st;i<=n;i++)
#define repd_0(st,n) for(i=st-1;i>=n;i--)
#define repd_1(st,n) for(i=st;i>=n;i--)
#define line string
typedef unsigned long long int UInt;
typedef long long int Int;
UInt q,y,i,x;
int flag=0;

int main(){
	ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	cin>>q>>y;
	while(y>q){
		x=sqrt(y);
		flag=0;
		for(UInt i=2;i<=x;i++){
			if(y%i==0){
				flag=1;
				break;
			}
		}
		if(flag==0){
			cout<<y;
			return 0;
		}
		y--;
	}
	cout<<-1;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
bool isprime[70000];
vector<int>lis;
int sieve()
{
    for (int i=2;i<70000;i++)
    {
        if (isprime[i]==0)
        {
            lis.push_back(i);
            for (int j=i*2;j<70000;j+=i)
            {
                isprime[j]=1;
            }
        }
    }
}
int main()
{
    sieve();
    int p,y;
    cin>>p>>y;
    int x=y;
    int flag=0;
    while (x>0)
    {
        flag=0;
        for (int i=0;i<lis.size();i++)
        {
            if (lis[i]>min(p,x))
            {
                break;
            }
            if (x%lis[i]==0)
            {
                flag=1;
                break;
            }
        }
        if (flag==0)break;
        x--;
    }
    if (x==1)printf ("-1\n");
    else printf ("%d\n",x);
}

#include<bits/stdc++.h>
using namespace std;
int p,y;
int main()
{
    scanf("%d%d",&p,&y);
    for(;y>=2;y--)
    {
        if(y<=p)
        {
            printf("%d\n",-1);
            return 0;
        }
        bool ok=1;
        for(register int i=2;i*i<=y&&i<=p;i++)
        {
        if(y%i==0)
        {
            ok=false;
            break;
        }
        if(ok)
        {
            printf("%d\n",y);
            return 0;
        }
    }
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
	int p, y, x;
	bool flag, jk;
	while(cin >> p >> y) {
		x = p + 1;
		flag = false;
		while(x <= y) {
			jk = true;
			for(int P = 2; P <= p; P++) {
				if(x % P == 0) {
					jk = false;
					break;
				}
			}
			if(jk) {
				cout << x << "\n";
				flag = true;
			}
			if(flag) break;
			x++;
		}
		if(!flag) cout << -1 << "\n";
	}
	return 0;
}

#include<bits/stdc++.h>
#define mp make_pair
#define ss second
#define ff first
#define ll long long int
#define tcase ll t;cin>>t;while(t--)
#define sz(a) int((a).size())
#define pb push_back
#define present(c,x) (�.find(x) != �.end())
#define cpresent(c,x) (find(all�,x) != �.end())
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define Yes cout<<"Yes\n";
#define No cout<<"No\n";
#define yes cout<<"yes\n";
#define no cout<<"no\n";
#define f(i,a) for(int i=0;i<a;i++)
#define in insert
#define matrix vector<vector<ll> >
#define e endl
const ll M=1000000000;

using namespace std;
/*
ll modexpo(ll a,ll b,ll p)
{
    ll ans=1;
      a=a%p  // update a if(a>=p)

        if(a==0)
            return 0;

                while(b!=0)
                {
                    if(b%2==1)
                        ans=(ans*a)%p;

                    a=a*a;
                    b=b/2;

                }
                return ans;
}*/
/*
ll countbit(ll n)
{
    ll c=0;
    while(n!=0)
    {
        c+=n&1;
        n>>=1;
    }
    return c;
}*/
/*ll countbit(ll n)
{
    ll c=0;
    while(n)
    {
        c+=n&1;
        n>>=1;
    }
    cout<<c<<e;
    return c;

}
  */

 /* vector<int> prime1;
  int prime[10000001];

void sieve(int n)
{
       for(long long i=2;i<=n;i++)
       {
         if(prime[i]==0)
         {  prime[i]=i;
            prime1.pb(i);
         }

            for(long long j=0;j<sz(prime1) && prime1[j]<=prime[i] && i*prime1[j]<=n;j++)
            {

                   prime[i*prime1[j]]=prime1[j];

            }

      }

 return ;
}*/

void fastio()
{
       ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);

}

int main()
{
    fastio();
      int p,y;
      cin>>p>>y;

      for(ll i=y;i>p;i--)
      {
          bool f=1;
          for(int j=2;j*j<=y && j<=p;j++)
          {
              if(i%j==0)
                f=0;
                break;
          }
          if(f)
          {
              cout<<i;
              return 0;
          }
      }
      cout<<"-1";

    return 0;
}

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
#include<vector>
#include<set>
#include<queue>
using namespace std;
const int maxn=1010;
const int INF=0x3f3f3f3f;
int main()
{
	long long int p,y;
	cin>>p>>y;
	int flag=0,c=0;
	if(y%2==0)
	y--;
	for(int i=y;i>=p;i-=2)
	{
		flag=0;
		for(int j=3;j*j<=i&&j<=p;j++)
		{
			if(i%j==0)
			{
				c=1;
				break;
			}
		}
		if(!c)
		{
			cout<<i<<endl;
			flag=1;
			break;
		}
	}
	if(!flag)
	cout<<-1<<endl;
 }

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

int main()
{
    ios_base::sync_with_stdio(false);

    int p, y; cin >> p >> y;

    for(int i = y; i >= p; i--)
    {
        bool good = true;
        int sq = sqrt(i);
        for(int j = 2; j <= min(p, sq); j++)
        {
            if(i % j == 0)
            {
                good = false;
                break;
            }
        }
        if(good)
        {
            cout << i;
            break;
        }
        else if(i == p)
        {
            cout << -1;
            break;
        }
    }

    int xyz; cin >> xyz; return 0;
}

#include<bits/stdc++.h>
using namespace std;
int prime[1000000],vis[100005],ans;
int Eular(int n)
{
    ans = 0;
    memset(vis,0,sizeof(vis));
    for(int i=2;i<=n;i++)
    {
        if(!vis[i])
            prime[ans++] = i;
        for(int j=0;i*prime[j]<=n;j++)
        {
            vis[i*prime[j]] = 1;
            if(i%prime[j]==0)
                break;
        }
    }
    return ans;
}
int main()
{
    int n,m;
    cin>>m>>n;
    int ans = Eular(n);
    int cnt = prime[ans-1];
    if(cnt<=m)
        cout<<-1<<endl;
    else
        cout<<cnt<<endl;
    return 0;
}

/* Dejwo to ziomal */

#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int p,y; cin>>p>>y;
    int j=2;
    for(long long i=y; i>p; i--)
    {
        bool pierwsza = true;
        do
        {
            if(i%j == 0)
            {
                pierwsza=false;
                break;
            }
            j++;
        }while(j*j <= p);

        if(pierwsza)
        {
            cout<<i<<"\n";
            return 0;
        }
    }

    cout<<-1<<"\n";
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long y,p,i,x=2,j;
    cin>>p>>y;
    if((y/p)<2)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    for(i=y; i>p; i--)
    {
        for(j=p; j>1; j--)
        {
            if(i%j==0)
            {
                x=1;
                break;
            }
            else
            {
                x=0;
            }
            //cout<<i<<j<<x<<endl;
        }
        if(x==0)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<"-1"<<endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
int p,y;
int isPrime(int num)
{
  for (int i=2; i<=sqrt(p) ; i++)
     if (num%i==0)
        return 0;

  return 1;
}

int main()
{

  cin>>p>>y;
if(p==2 && y%2!=0){cout<<y ; return 0;}

if(y-p ==1  && y%2==0){cout<<"-1"; return 0;}

while(y>(p/2)){  if(isPrime(y)==1) {cout<<y; return 0;}  y--;}
 cout<<"-1";
    return 0;
}

#include <bits/stdc++.h>

#define f first
#define s second
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

#define x1 aseasfd
#define y1 sadasd
#define left come
#define right sdsfd

using namespace std;

const int maxn = 1e6 + 7;
const ll inf = 1e9 + 7;
const ll mod = 1e9 + 7;
const ld eps = (ld)1e-12;
const double pi = 3.141592653;
const ll linf = 1e18 + 7;
const int logn = 20;

ll p,y;

bool prime (ll x) {
	if (x == 2)return true;
	else if (x % 2 == 0)return false;
	else {
		for (int i = 3; i * i <= x; i ++) {
			if (x % i == 0)return false;
		}
		return true;
	}
}

int main () {

cin >> p >> y;

for (ll i = y; i > p; i --) {
	if (prime(i)) {
		cout << i;
		return 0;
	}
}
cout << -1;

return 0;
}

#include<bits/stdc++.h>
using namespace std;

int tab[]={2, 3, 5, 7};
long long qpow(int a, int b, int r)
{
    long long ret = 1, tmp = a;
    while(b)
    {
        if (b&1)
            ret = ret*tmp%r;
        tmp = tmp*tmp%r;
        b >>= 1;
    }
    return ret;
}
bool  Miller_Rabbin(int n, int a)
{
    int r = 0, s = n-1, j;
    long long k;
    if(n%a == 0)    return false;
    while((s&1) == 0)
    {
        s >>= 1;
        r++;
    }
    k = qpow(a, s, n);
    if(k == 1)  return true;
    for (j = 0; j < r; j++, k=k*k%n)
        if (k == n-1)
            return true;
    return false;
}
int Isprime(int n)
{
    for (int i = 0; i < 4; i++)
    {
        if (n == tab[i])
            return n;
        if (!Miller_Rabbin(n, tab[i]))
            return -1;
    }
    return n;
}

int main()
{
    ios::sync_with_stdio(false);
    int p,y;
    while(cin>>p>>y)
    {
        int ans=-1;
        for(int i=y;i>p;i--)
        {
            ans=Isprime(i);
            if(ans!=-1) break;
        }

        cout<<ans<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define rep(i,k,n) for(int (i) = int(k); i < int(n); ++i)

int minf(int x){
    int d = 2;
    while(x and d*d <= x){
        if(x%d) return d;
        ++d;
    }
    return x;
}

int main(){
    int p, y;
    cin >> p >> y;
    const int N = 1e9;
    int ans = -1;
    vector<bool> v(N + 1, true);
    //rep(i,2,p+1) v[i] = false;
    for(int i = y; i > p;--i){
        if(minf(i) > p){
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define len(a) sizeof(a)/sizeof(*a)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define pb push_back

typedef long long ll;
inline ll gcd(ll a, ll b) {ll r; while (b != 0) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}

bool isPrime(int n){
    if(n < 2){
        return false;
    }
    for(int i = sqrt(n);i >= 2;i--){
        if(n % i == 0)
            return false;
    }
    return true;
}

void solve(){
    int p,y;
    cin >> p >> y;
    if(!(p&1)){
        if(y&1){
            cout << y << endl;
        }else{
            cout << y - 1 << endl;
        }
        return;
    }
    for (int i = y; i > p;i--){
        if((i&1) && isPrime(i)){
            cout << i << endl;
            return;
        }
    }
    cout << -1 << endl;

}

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}

#include <iostream>
#include <cmath>

using namespace std;

bool div(int y)
{
    int lim = y < int(sqrt(y))? y : int(sqrt(y));
    for (int i = 3; i <= lim; ++i){
        if (y % i == 0) return false;
    }
    return true;
}

int main()
{
    int p, y;
    cin >> p >> y;
    if (y % 2 == 0) --y;
    for (int i = y; i > p; i -= 2){
        if (div(i)){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
bool primecheck(long long x_primecheck)
{
	if(x_primecheck<2||(x_primecheck>2&&x_primecheck%2==0)) return 0;
	for(long long i_primecheck=3;i_primecheck*i_primecheck<=x_primecheck;i_primecheck+=2)
		if(x_primecheck%i_primecheck==0)
			return 0;
	return 1;
}
long long x,y;
int main()
{
	cin>>x>>y;
	for(int i=x+1;i<=y;i++)
	{
		if(primecheck(i))
		{
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<"-1"<<endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define forn(i, n) for (int i = 0; i < (n); i++)
#define dforn(i, n) for (int i = (n); i >= 0; i--)
#define sz(a) int((a).size())
#define debug(v) cerr << #v << " = " << (v) << endl;
#define debugc(c) forn(i, sz(c)) cerr << #c << "[" << i << "] = " << (c)[i] << endl;
typedef long long ll;

#define MOD (int(1e9+7))

int main() {
	ios::sync_with_stdio(false);

	int p,n; cin >> p >> n;

	list<int> ls;
	ls.push_back(2);

    for (int p=3; p<=n; p++)    {

        bool div = false;
        for (auto i : ls) {

			if (i > (p/2)) {
				break;
			}
			if (p % i == 0) {
				div = true;
				break;
			}

		}
		if (! div) {
			ls.push_back(p);
		}
    }
    for (auto  i = ls.end(); i != ls.begin(); i--) {
		if (*i <= n) {
			if (*i <= p) {
				cout << "-1\n";
			} else {
				cout << *i << "\n";
			}
			return 0;
		}
	}

	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
ll p , y  , st ;
int main ()
{
    ios_base::sync_with_stdio(0);
    cin>>p>>y;
    for( ll i = y ; i >= 0 ; i -- ){
            ll x = sqrt(i) , t = 1 ;
        for( ll j = 2 ; j <= x ;  j ++  ){
            if( x % j == 0  )  { t=0;break ;}
        }
        if( t == 1 ) st=i;
    }
    for( ll i = y ; i >= st ; i -- ){
            ll t = 0 , x = sqrt(p) ;
        for( ll  j = 2 ; j <= min(p,x); j ++ ){
            if( i %j == 0) {t=1;break ;}
        }
    if( t == 0 && i >  p  ) {cout<<i;return 0;}
    }
    cout<<-1;
    return 0;
}
/**
**/

#include <cstdio>
int main()
{
    int p,y;
    scanf("%d%d",&p,&y);
    int b;
    if(p>=y)
    {
        printf("-1");
        return 0;
    }
    for(int a = y;a > p;a --)
    {
        for( b = 2;b*b <= p+1;b ++)
        {
            if(a%b==0)
                break;
        }
        if(b*b>p+1)
        {
            printf("%d",a);
            return 0;
        }
    }
    printf("-1");
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int p,n;
    cin >> p >> n;
    if(p==n){
        cout<<-1;
        return 0;
    }
    int ar[300]={0};
    for(int i=n;i>(n-300)&&i>1&&i>p;i--){
        ar[n-i]=i;
    }
    for(int j=0;j<300;j++){
        if(ar[j]==0)
            continue;
        for(int i=2;(i)<=min((int)sqrt(n),p);i++){
            if(ar[j]%i==0 || ar[j]%(ar[j]/i)==0){
                //cout<<ar[j]<<","<<ar[j]/i<<endl;
                ar[j]=0;
                ar[ar[j]/i]=0;
                break;
            }
        }
    }
    int mx = -1;
    for(int i=0;i<300;i++){
        mx = max(mx,ar[i]);
    }
    if(mx==0)
        cout<<-1;
    else
        cout<<mx;
    return 0;
}

#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <fstream>
#include <limits.h>
using namespace std;
typedef long long ll;
bool is_prime (ll n)
{
	if (n==2) return true;
	int u = ceil(sqrt((double)n));
	for (int i = 2;i<=u;i++)
	{
		if (n%i==0) return false;
	}
	return true;
}
int main ()
{
	ll p,y;
	cin>>p>>y;
	int cur = 2;
	int ans = 1;
	while (true)
	{
		if (is_prime (cur) && cur <= p)
		{
			ans *= cur;
		}
		cur++;
		if (cur > p) break;
	}
	if (ans - 1 <= y)
	cout<<ans - 1;
	else
	cout<<-1;
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:100000000000")

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <complex>

using namespace std;
#define FR(i, n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i, c, n) for(int (i)=(c);(i)<(n);(i)++)
#define REP(it, v, cont) for(cont::iterator (it)=(v).begin();(it)!=(v).end();++(it))
#define CLR(a, c) memset((a),(c),sizeof (a))
#define ALL(v) (v).begin(),(v).end()
#define SQR(a) ((a)*(a))
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;

bool isprime(int n){
    if(n<2) return false;
    for(int i=2;i*i<=n;++i)
        if(n%i==0) return false;
    return true;

}

using namespace std;

int main() {
//    freopen("a.in", "r", stdin);
    ll a,b;
    cin>>a>>b;
    ll res=-1;
    for(int i=b;i>a;i--){
        if(isprime(i)){
            res=i;
            break;
        }

    }
    cout<<res<<endl;

}

#include<bits/stdc++.h>
using namespace std;
bool prime[100005];
int is_prime[10000005];
int Eular(int n,int m)
{
    int l = 1;
    for(int i=2;i<=m;i++)
    {
        if(!prime[i])
        {
            is_prime[l++] = i;
            for(int j=2*i;j<=m;j+=i)
            {
                if(j<=100005)
                    prime[j] = true;
            }
        }
    }
    return l-1;
}
int main()
{
    int n,m;
    int ans;
    cin>>n>>m;
    ans = Eular(n,m);
    if(ans==1)
        cout<<-1<<endl;
    else
    {
        if(is_prime[ans]<=n)
            cout<<-1<<endl;
        else
            cout<<is_prime[ans]<<endl;
    }
    return 0;
}

#include<iostream>
#include <bitset>
#include<vector>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
ll _sieve_size; bitset<1000000010> bs; vi primes;
void sieve(ll upperbound) { _sieve_size = upperbound + 1; bs.set();
bs[0] = bs[1] = 0;
for (ll i = 2; i <= _sieve_size; i++) if (bs[i]) {
for (ll j = i * i; j <= _sieve_size; j += i) bs[j] = 0;
primes.push_back((int)i); } }
bool isPrime(ll N) {
if (N <= _sieve_size) return bs[N];
for (int i = 0; i < (int)primes.size(); i++)
	if (N % primes[i] == 0) return false;
return true; // it takes longer time if N is a large prime!
}

int main()
{
	ll p,y;
	bool found=false;
	int res;
	cin >> p >> y ;
    ll s;
    s= p<=sqrt(y)?p:sqrt(y);
    bs.set();
	bs[0] = bs[1] = 0;
    for (ll i = 2; i <= s; i++)
    {
        ll m = i * i ;
        if (m >=p && m <= y && bs[i])
        {
            for (ll j = i * i; j <= y; j += i) bs[j] = 0;
        }
    }
    for(ll i=y;i>p;i--)
    {
        if(bs[i])
        {
            found=true;
            res=i;
            break;
        }
    }
	cout<< (found?res:-1) << endl;
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include<map>
#include<math.h>
#include <bits/stdc++.h>

using namespace std;

long long int fact(long long int n)
{
    for (long long int i=2;i<=sqrt(n);i++ )
    {
        if (n%i==0)
        {
            return i;
        }
    }
    return n;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt" , "r" , stdin) ;
        freopen("output.txt" , "w" , stdout) ;
    #endif
    long long int p,y;
    cin>>p>>y;
    long long int branch=y;
    while (branch>p)
    {
        long long int div=fact(branch);
        if (div==branch)
        {
            cout<<branch<<endl;
            break;
        }
        else
        {
            branch--;
        }
    }
    if (branch==p)
    {
        cout<<-1<<endl;
    }
}

///...................................*****.................................................///
///                  Mujahidul Islam ( mujahidulislam2923@gmail.com )                       ///
///                  Department of Ict                                                      ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///

#include<bits/stdc++.h>
///#include <ext/pb_ds/assoc_container.hpp>
///#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
///using namespace __gnu_pbds;
///template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define          CIN                    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define          ll                     long long int
#define          ull                    unsigned long long int
#define          db                     double
#define          pii                    pair < int, int>
#define          pll                    pair < ll, ll>
#define          MOD                    1000000007
#define          vi                     vector<int>
#define          vl                     vector<ll>
#define          pb                     push_back
#define          sc                     scanf
#define          pf                     printf
#define          scin(x)                scanf("%d",&(x))
#define          scin2(x,y)             scanf("%d %d",&(x),&(y))
#define          scln(x)                scanf("%lld",&(x))
#define          scln2(x,y)             scanf("%lld %lld",&(x),&(y))
#define          min3(a,b,c)            min(a,min(b,c))
#define          min4(a,b,c,d)          min(d,min(a,min(b,c)))
#define          max3(a,b,c)            max({a,b,c})
#define          max4(a,b,c,d)          max(d,max(a,max(b,c)))
#define          ms(a,b)                memset(a,b,sizeof(a))
#define          mp                     make_pair
#define          gcd(a, b)              __gcd(a,b)
#define          lcm(a, b)              ((a)*(b)/gcd(a,b))
#define          input                  freopen("input.txt","rt", stdin)
#define          output                 freopen("output.txt","wt", stdout)
#define          PI                     3.141592653589793238462643
#define          rep( i , a , b )       for( i=a ; i<b ; i++)
#define          rev( i , a , b )       for( i=a ; i>=b ; i--)
#define          repx( i ,a,b, x)       for( i=a ; i<b ; i+=x)
#define          RUN_CASE(t,T)          for(__typeof(t) t=1;t<=T;t++)
#define          zero(a)                memset(a,0,sizeof a)
#define          all(v)                 v.begin(),v.end()
#define          Lower(c,x)             (lower_bound(c.begin(),c.end(),x)-c.begin())
#define          Upper(c,x)             (upper_bound(c.begin(),c.end(),x)-c.begin())
#define          CASEL(t)               printf("Case %d:\n",t)
#define          Unique(X)              (X).erase(unique(all(X)),(X).end())

///priority_queue<int,vector<int>,greater<int> >pq;
///string str = "abcdefghijklmnopqrstuvwxyz";
///string s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;

///---------------Order set-------------------
///template<typename T> using orderset =tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
///#include <ext/pb_ds/assoc_container.hpp>
///using namespace __gnu_pbds;
///*os.find_by_order(index) os.order_of_key(value)

///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------
///sort( all( v ) ) ;

vector<ll>prime;
ll p , q , val ;

void findPrime()
{
    ll n=100000;
    ll i,j;
    bool mark[n+1];

    memset(mark,false,sizeof mark);

    for( i=4; i<=n; i=i+2)
    {
        mark[i]=true;
    }

    mark[1]=true;

    for( i=3; i<=n; i=i+2)
    {
        if(mark[i]==false)
        {
            for( j=2; i*j<=n; j++)
            {
                mark[i*j]=true;
            }
        }
    }
    for(i=1; i<=n; i++)
    {
        if(mark[i]==false)
        {
            prime.push_back(i);
        }
    }
}

ll segmentedSieve(ll a,ll b)
{
    ll i,p,j;
    bool arr[b-a+1];
    memset(arr,false,sizeof arr);

    if(a==1)
    {
        a++;
    }
    ll sqrtb=sqrt(b);

    for( i=0; i<prime.size() && prime[i]<=sqrtb; i++)
    {
        p=prime[i];
        j=p*p;
        if(j<a)
        {
            j=((a+p-1)/p)*p;
        }
        for(; j<=b; j=j+p)
        {
            arr[j-a]=true;
        }
    }

    for(i=a; i<=b; i++)
    {
        if(arr[i-a]==false)
        {
            if( i > q )
            {
                cout << -1 << endl ;
            }
            else
            {
                cout << q / i * i << endl ;
            }
            exit( 0 ) ;
        }
    }
}

int main()
{
    CIN ;
    findPrime() ;
    cin >> p >> q ;
    ll c = segmentedSieve( p + 1 , p + 1000000 ) ;
    return 0 ;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 10000006;
vector<ll> prime;
bool mark[N];

void sieve()
{
    ll limit = sqrt(N) + 5;
    mark[1] = true;
    prime.push_back(2);
    for (ll i = 4; i < N; i += 2)
        mark[i] = true;
    for (ll i = 3; i < N; i += 2)
    {
        if (!mark[i])
        {
            prime.push_back(i);
            if (i <= limit)
                for (ll j = i * i; j < N; j += 2 * i)
                    mark[j] = true;
        }
    }
}

vector<pair<ll, ll>> factor;
void factorize(ll n)
{
    for (ll i = 0; i < prime[i] and prime[i] * prime[i] <= n; i++)
    {
        if (n % prime[i] == 0)
        {
            ll cnt = 0;
            while (n % prime[i] == 0)
            {
                cnt++;
                n /= prime[i];
            }
            factor.push_back(make_pair(prime[i], cnt));
        }
    }
    if (n > 1)
    {
        factor.push_back(make_pair(n, 1));
    }
}
int main()
{
    sieve();
    int a, b;
    cin >> a >> b;
    int temp = -1;
    ll t = sqrt(b) + 2;
    t = b - t;

    for (ll i = b; i >= t; i--)
    {
        factor.clear();
        factorize(i);
        bool tu = true;
        for (ll j = 0; j < factor.size(); j++)
        {
            if (factor[j].first <= a)
            {
                tu = false;
            }
        }
        if (tu)
        {
            cout << i << "\n";
            return 0;
        }
    }
    cout << temp << "\n";
}

#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
ll p , y  , st ;
int main ()
{
    ios_base::sync_with_stdio(0);
    cin>>p>>y;
    for( ll i = y ; i >= 0 ; i -- ){
            ll x = sqrt(i) , t = 1 ;
        for( ll j = 2 ; j <= x ;  j ++  ){
            if( x % j == 0  )  { t=0;break ;}
        }
        if( t == 1 ) st=i;
    }
    for( ll i = y ; i >= y-100 ; i -- ){
            ll t = 0 , x = sqrt(p) ;
        for( ll  j = 2 ; j <= min(p,x); j ++ ){
            if( i %j == 0) {t=1;break ;}
        }
    if( t == 0 && i >  p  ) {cout<<i;return 0;}
    }
        if( st > p ) cout<<st;
        else
    cout<<-1;

    return 0;
}
/**
**/

#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main() {
    ll p,y,x,i,flag=0,cnt=0,mx=0;
    cin>>p>>y;
    x = 2;
    vector<ll> vi;
    while(x<y){
        flag=0;
        for(i=2;i<=sqrt(x);i++){
            if(x%i == 0){
                flag=1;
                break;
            }
        }
        if(flag == 0){
            mx = max(mx,x);
        }
        x++;
    }

    sort(vi.rbegin(),vi.rend());
    for(i=2;i<=p;i++){
        if(i == mx){
            cnt=1;
            break;
        }
    }
    if(cnt==1){
        cout<<"-1";
    }
    else{
        cout<<mx;
    }

}

/*
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░LAUNCH GOOSE, WORKERS░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░▄▀▀▀▄░░░░░░░░░░░░░░░░░░
░░░░░▄███▀░◐░░░▌░░░░░░░░░░░░░░░░░
░░░░░░░░░▌░░░░░▐░░░░░░░░░░░░░░░░░
░░░░░░░░░▐░░░░░▐░░░░░░░░░░░░░░░░░
░░░░░░░░░▌░░░░░▐▄▄░░░░░░░░░░░░░░░
░░░░░░░░░▌░░░░▄▀▒▒▀▀▀▀▄░░░░░░░░░░
░░░░░░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄░░░░░░░░
░░░░░░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄░░░░░░
░░░░░░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄░░░░
░░░░░░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄░░
░░░░░░░░░░░░░░░░▌▌░▌▌░░░░░░░░░░░░
░░░░░░░░░░░░░░░░▌▌░▌▌░░░░░░░░░░░░
░░░░░░░░░░░░░░▄▄▌▌▄▌▌░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;
vector<ll> ans,ans1;
ll n1,f1,n,i,j,x,f,m,l,r,a[2000000],p[2000000],b[2000000];
int main()
{
    for (i=2; i<=45000; i++)
    if (!a[i])
     {
      x=i*i;
      while (x<=45000)
      {
       a[x]++;
       x+=i;
      }
     }
    for (i=2; i<=45000; i++) if (!a[i]) p[m++]=i;
     cin>>f>>f1;
     l=f;
     r=f1;
     n=r-l;
     for (ll i=0; i<=n; i++) b[i]=0;
     for (ll i=0; i<m; i++)
     {
      x=p[i];
      j=x*x-l;
      if (j<0) j=(j%x+x)%x;
      while (j<=n)
      {
       b[j]=1;
       j+=x;
      }
     }
     for (ll i=0; i<=n; i++) if(!b[i])  if (i+l>1)ans.push_back(i+l);

     l=1;
     r=f;
     n=r-l;
     for (ll i=0; i<=n; i++) b[i]=0;
     for (ll i=0; i<m; i++)
     {
      x=p[i];
      j=x*x-l;
      if (j<0) j=(j%x+x)%x;
      while (j<=n)
      {
       b[j]=1;
       j+=x;
      }
     }
     for (ll i=0; i<=n; i++) if(!b[i])  if (i+l>1)ans1.push_back(i+l);

    ll mx=-1,edd;
    for(auto i : ans)
    {
        edd=0;
        for(auto j : ans1) if(i%j==0)
        {
            edd++;
            break;
        }
        if(edd) continue;
        mx=max(i,mx);
    }
    if(mx<=f) return cout<<-1,0;
    cout<<mx;
    return 0;
}

#include<iostream>
#include<string.h>
#include<algorithm>
#include<cstdio>
#include<math.h>
using namespace std;

int main() {
	long p,y,i,j,n;
	cin >> p >> y;
	if (p == y || (y - 1 == p && (y % 2 == 0))) {
		printf("-1\n");
		return 0;
	}
	i = y;
	while (i > p) {
		for (j = 2; j <= p&&j*j<=y; j++)if (!(i%j))break;
		if (j == p + 1) {
			printf("%ld\n", i);
			return 0;
		}
		--i;
	}
	if (i==p)printf("-1\n");
}

#include <cstdio>
#include <vector>

using namespace std;

int pr[32000] = {0};
vector<int> prime;

int isPrime(int x)
{
	for(int i = 2; i * i <= x; i++)
	{
		if(x % i == 0) return -1;
	}

	return 1;
}

void primeTable()
{
	int i = 2;
	pr[2] = 1;
	prime.push_back(2);

	while(i < 32000)
	{
		if(pr[i] == -1)
		{
			i++;
		}
		else if(pr[i] == 1)
		{
			int j = 2;
			while(i * j < 32000)
			{
				pr[i * j] = -1;
				j++;
			}

			i++;
		}
		else
		{
			pr[i] = isPrime(i);
			if(pr[i] == 1) prime.push_back(i);
		}
	}
}

int main()
{
	int y, p;
	primeTable();
	scanf("%d %d", &y, &p);

	int i;

	int flag = 0;
	for(i = p; i > y; i--)
	{
		flag = 0;
		for(vector<int>::iterator it = prime.begin(); (*it) * (*it) <= i; it++)
		{
			if(i % (*it) == 0)
			{
				flag = 1;
				break;
			}
		}

		if(!flag)
		{
			printf("%d\n", i);
			break;
		}
	}

	if(i == y) printf("-1\n");

	return 0;
}

#include <iostream>
#include<algorithm>
#include<string>
#include<map>
#include <iterator>
#include<iomanip>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<stdio.h>
#include<set>
#include <functional>

#define mod 1000000007
#define mod2 30000000
#define pa(a,b) make_pair(a,b)
#define f first
#define s second
#define pb(a)  push_back(a)
#define all(a) a.begin() , a.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define LL  long long int
#define oo 1e9
#define pi 3.14159265359
#define eps  1e-9
LL maxx(LL a , LL b){ return a>b ?  a : b ;}
LL minn(LL a , LL b){ return a>b ?  b : a ;}

using namespace std;
int dx[] = {1 , 1 ,1 , 0 , 0  , -1 , -1  , -1  , 0 };
int dy[] = { -1 , 0  , 1 , 1 , -1 , 0 , 1 , -1 , 0 };
void boostIO()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
LL gcd(LL a, LL b) {
    return b == 0 ? a : gcd(b, a % b);
}
LL lcm(LL a , LL b )
{
    return (a*b)/gcd(a , b);
}
LL poww(LL base, LL exp){
  base %= mod;
  LL result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % mod;
    base = (base * base) % mod;
    exp >>= 1;
  }
  return result;
}
bool is_prime(int x)
{
    if(x == 2)
        return 1 ;
    for(int i = 2 ; i * i <= x ; i++)
       if(x % 2 == 0)
          return 0 ;
    return 1 ;
}
int main()
{
    int p , y ; cin>>p>>y ;
    if(p >= 100){
    for(int i = y ; i > p ; i--){
        if(is_prime(i))
            return cout<<i , 0 ;
    }
    cout<< -1 ;
    return 0 ;
    }
    else {
        for(int i = y ; i > p ; i--){
            bool fnd = 1 ;
            for(int j = 2 ; j <= p ; j++)
            if(i % j == 0){
                fnd = 0 ;
                break;
            }
            if(fnd)
                return cout<<i , 0 ;
        }
        cout<<-1 ;
        return 0 ;
    }
}

#include <bits/stdc++.h>
using namespace std;
#define gg getchar();getchar();
typedef pair<int, int> ii;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long long ll;
typedef pair<ll, ll> lii;

int main() {
    int p,y;
    cin >> p >> y;
    for(int i = y; i > p; i--) {
        bool f= false;
        for(int j = 2; 1LL*j*j <=p; j++) {
            if(i%j==0) {
                f = true;
            }
        }

        if(!f) {
            cout << i;gg
            return 0;
        }
    }

    cout << -1;

    gg
}

/*
    Author : Bute_Forces || sarthak0797
*/

#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define pii pair < int , pair < int , int > >
#define pi pair < int , int >
#define pp pair < ll , ll >
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define c1(a) cout << setprecision(9) << #a << ' ' << a << "\n";
#define c2(a,b) cout << #a << ' ' << a << ' ' << #b << ' ' << b << "\n";
#define fo(i,n) for(auto i = 0; i < n; i++)
#define PI 3.1415926

int isprime(int num)
{

}
int main()
{
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,p;
    cin >> p >> n;
    if(n == p)
    {
        cout << "-1";
        return 0;
    }
    for(ll i = n; i > p; i--)
    {
        int primeCount = 0;
        for(ll j = 2; j <= sqrt(i); j++)
        {
            if(i % j == 0)
            {
                primeCount++;
                break;
            }
            if(j < p) break;
        }
        if(primeCount == 0)
        {
            cout << i;
            return 0;
        }
    }
    cout << "-1";
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b;

bool isPrime(ll x) {
    for (int d = 3; (d <= a) and (d*d < x); d+=2) {
        //cout << d << " ";
        if (x % d == 0){
            //cout << endl << x << " falhou aqui " << d << endl;
            return false;
        }
    }
    return true;
}

int main(){
    scanf("%lld%lld",&a,&b);
    for(ll i=(b%2?b:b-1);i>a;i-=2){
        ////cout << i << ": ";
        if(isPrime(i))return 0*printf("%d",i);
        //cout << endl;
    }
    printf("-1");
    return 0;
}

#include<bitset>
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<functional>
#include<iterator>
#include<locale>
#include<memory>
#include<stdexcept>
#include<utility>
#include<string>
#include<fstream>
#include<ios>
#include<iostream>
#include<iosfwd>
#include<iomanip>
#include<istream>
#include<ostream>
#include<sstream>
#include<streambuf>
#include<complex>
#include<numeric>
#include<valarray>
#include<exception>
#include<limits>
#include<new>
#include<typeinfo>
#define sqr(x) (x*x)
#define fp pop_front
#define bp pop_back
#define pf push_front
#define pb push_back
#define mp make_pair
#define sz size()
#define se second
#define fi first
#define y1 yy1
#define _ std::ios_base::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int I;
const ld pi = acos(-1);
const ll mod = 1e9 + 7;
const ll N = 1e6 + 500;
const ll INF = 1e18 + 7;

int a, b;

int main()
{
	scanf("%d%d", &a, &b);
	while(b)
	{
		printf("%d\n", b);
		if(b == a)
		{
			printf("-1");
			return 0;
		}
		bool ok = false;
		for(int i = 2; i * i <= b; ++i)
		{
			if(b % i == 0 && i <= a){
				ok = true;
				break;
			}
		}
		if(!ok)
		{
			printf("%d", b);
			return 0;
		}
		b--;
	}
	printf("-1");
	return 0;
}

/*"Nothing is true."*/
#include<bits/stdc++.h>
using namespace std;
inline int min(int _a, int _b) {return _a < _b ? _a : _b;}
inline int max(int _a, int _b) {return _a > _b ? _a : _b;}
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;

template <class _T> inline void rd(_T &_a) {
	int _f=0,_ch=getchar();_a=0;
	while(_ch<'0' || _ch>'9'){if(_ch=='-')_f=1;_ch=getchar();}
	while(_ch>='0' && _ch<='9')_a=(_a<<1)+(_a<<3)+_ch-'0',_ch=getchar();
	if(_f)_a=-_a;
}

long long p, y, x;

bool ispri[40] = {0, 0, 1, 1, 0, 1,
	0, 1, 0, 0, 0,
	1, 0, 1, 0, 0,
	0, 1, 0, 1, 0,
	0, 0, 1, 0, 0,
	0, 0, 0, 1, 0};

long long cha;

int main() {
	//freopen("CF937B.in","r",stdin);
	//freopen("CF937B.out","w",stdout);
	rd(p); rd(y); x = 1; cha = y - 1;
	for(int i = 1;i <= p; ++i) {
		if(ispri[i] == 0) continue;
		x *= i;
		if(x > y) break;
	}
	if(x > y + 1) puts("-1");
	else {
		for(int i = 1;i <= p; ++i) {
			if(x * i > y + 1) continue;
			cha = min(cha, y - x * i);
		}
		printf("%I64d\n", y - cha - 1);
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
typedef long long int_t;

int_t p, y;

bool input() {
  if (cin >> p >> y) return true;
  return false;
}

void solve() {
  int_t res = -1;
  for (int_t i = y; i > p; --i) {
    if (i % 2 == 0) continue;
    for (int_t j = 3; j <= p; j += 2) {
      if (i % j == 0) continue;
    }
    res = i;
    break;
  }
  cout << res << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  while (input()) {
    solve();
  }
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define debug(...)   printf( __VA_ARGS__ )
//#define debug(...)   /****nothing****/
#define pb push_back
#define mp make_pair
#define LL long long
#define resett(arr,val,N) for(int ii=0;ii<(N);ii++) arr[ii]=val;
#define PI 2*acos(0.0)
int n,x,p;
set<int> st;
bool flag[50000];
vector<int> prime;

void seive(int N) {

    for(int i=2; i*i<=N; i++)
        if(flag[i]==0)
            for(int j=i+i; j<=N; j+=i)
                flag[j]=1;

    for(int j=2; j<=N; j++)
        if(flag[j]==0)
            prime.push_back(j);

}

bool isok(int N) {

    int temp=N;
    for(int i=0; i<prime.size() && prime[i]*prime[i]<=N; i++)
        while(temp%prime[i]==0) {
            temp/=prime[i];
            if(prime[i]>=2 && prime[i]<=p)
                return 0;
        }

    if(temp==N)
        return 1;
    else {

        if(temp>=2 && temp<=p)
            return 0;
        else
            return 1;

    }

}

int main() {
    //freopen("e://i.txt","r",stdin);
    //freopen("e://o.txt","w",stdout);
    //ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) ;
    seive(40000);

    while(cin>>p>>n) {

        if(isok(n))
            printf("%d\n",n);
        else {

            {

                int i;

                for(i=n; i>=2; i--)
                    if(isok(i)) {
                        printf("%d\n",i);
                        break;
                    }

                if(i==p)
                    puts("-1");

            }

        }

    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int p, y;

int vis[1000005];
int pri[10000];
int cnt = 0;
void init() {
	for (int i = 2; i*i <= 1000000000; i++) {
		if (!vis[i]) pri[cnt++] = i;
		for (int j = i * i; j <= 1000000; j+=i)
			vis[j] = 1;
	}
}

bool jud(int x) {
	for (int i = 0; i < cnt; i++) {
		if (x <= pri[i]*pri[i]) break;
		if (x%pri[i] == 0) return false;
	}
	return true;
}

int main() {
	init();
	scanf("%d%d", &p, &y);
	int flag = -1;
	for(int i=y;i>=p+1;i--){
		if (jud(i)) {
			flag = i;
			break;
		}
	}
	cout << flag << endl;
	return 0;
}

#include <iostream>
#include <cmath>
using namespace std ;

inline bool prime(const int& n) {
	if (n > 2 && n % 2 == 0) return false ;
	for (int i = 3 ; i*i <= n ; i += 2) {
		if (n % i == 0) return false ;
	}
	return true ;
}

int main()
{

	int p , y ;

	cin >> p >> y ;

	if (p == y) {
		cout << -1 ;
		return 0 ;
	}

	if (y % 2 == 0) --y ;

	int mx = 0 ;

	for (int i = p ; i > 3 ; --i) {
		if (prime(i)) {
			mx = i ;
			break ;
		}
	}

	while (y > p) {
		int q = sqrt(y) ;
		if (prime(q)) {
			if (q > mx) {
				cout << y ;
				return 0 ;
			}
		}
		if (prime(y)) {
			cout << y ;
			return 0 ;
		}
		y -= 2 ;
	}

	cout << -1 ;

}

#include<bits/stdc++.h>
using namespace std;
# define ll long long  int

  int main (){
     ios_base::sync_with_stdio(0);
    int a,b;
    cin>>a>>b;
      if(a>=b){
          cout<<-1;
          return 0;
      }
    int  k=b-a;
      if(a<=1000000 && b<=1000000){

          int i ,j;
          int A[1000006];
          int flag=0;
          int ans=0;
          for(i=3;i<=1000000;i++){
              A[i]=1;
          }
          for(i=2;i<=a;i++){
              for(j=i;j<=b;j=j+i){
                  A[j]=0;
              }
          }
          for(i=3;i<=b;i++){
              if(A[i]==1){
                  ans=i;
                  flag=1;

              }
          }
          if(flag){
              cout<<ans;

              return 0;
          }
          cout<<-1;
          return 0;

      }
      if(a>1000){
      k=min(k,500);
      int i,j;
      int flag=0;
      int ans=0;
      int flag1=0;

        for(i=max(2,b-k);i<=b;i++){
            flag=0;
            for(j=2;j*j<=i;j++){
                if(i%j==0 ){

                    flag=1;
                }
            }
          if(flag==0){

              if(i>a){
                  flag1=1;
                  ans=i;
              }

          }
      }
      if(flag1){
          cout<<ans;
          return 0;
      }
      cout<<-1;
          return 0;
      }
      if(a<1000){
           k=min(k,1000);
      int i,j;
      int flag=0;
      int ans=0;
      int flag1=0;

        for(i=max(2,b-k);i<=b;i++){
            flag=0;
            for(j=2;j<=a;j++){
                if(i%j==0 ){

                    flag=1;
                }
            }
          if(flag==0){

              if(i>a){
                  flag1=1;
                  ans=i;
              }

          }
      }
      if(flag1){
          cout<<ans;
          return 0;
      }
      cout<<-1;
      }

      return 0;
  }

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

const int maxn=1e5+10;
int prime[maxn];
bool vis[maxn*1000];

void init(){
	int cnt=0;
	memset(vis,0,sizeof(vis));
	memset(prime,0,sizeof(prime));
	for(int i=2;i<maxn;i++){
		if(vis[i]==false)	prime[++cnt]=i;
		for(int j=1;j<=cnt&&i*prime[j]<=maxn;j++){
			vis[i*prime[j]]=true;
			if(i%prime[j]==0)	break;
		}
	}
	prime[0]=cnt;
}

int main(){
	init();
	int p,y;	cin>>p>>y;
	int pos=lower_bound(prime+1,prime+prime[0]+1,y)-prime-1;
	cout<<(prime[pos]>p&&pos!=0?prime[pos]:-1)<<endl;
	return 0;
}

#include <iostream>

using namespace std;

int minimal(int y, int p)
{
    for (int i = 2; i <= p && i * i <= y; i++)
        if (y % i == 0) return (1);
    return (0);
}

int main(void)
{
    int y, p;

    cin >> p >> y;
    while (minimal(y, p))
    {
        y--;
    }
    if (y != 1) cout << y; else cout << -1;
    return (0);
}

#include <bits/stdc++.h>

using namespace std;

/*from 2 to y so number of branches is y-2+1 -> y-1
p é ate qual galho tem grasshopers, ou seja, se p = 5, começar os calculos do galho 5*/

int main() {
	int p,y;
	scanf("%d %d", &p, &y);
	int v[y+1];
	for(int i=1;i<=y;i++){
		v[i] = 0;
	}
	//primeiro galho n conta
	v[1]++;
	for(int i=2;i<=p;i++){
		for(int j=1; j<=(y/j);j++){
			v[i*j]++;
		}
	}

	int condi = 0;
	for(int i=y;i>=1;i--){
		if(v[i] == 0){
			condi = 1;
			printf("%d\n", i);
			break;
		}
	}
	if(!condi)
		printf("-1\n");
	return 0;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    ll p,y;
    cin>>p>>y;
    for(ll i=y;i>=2;i--)
    {
        int f=1;
        for(ll j=2;j<100 && j<=p;j++)
        {
            if(i%j==0)
            {
                f=0;
                break;
            }
        }
        if(f==0)
        {
            continue;
        }
        else
        {
            cout<<i;
            return 0;
        }
    }
    cout<<-1;
}

#include<iostream>
using namespace std;

bool isPrime(int n)
{
	int i;
	for ( i = 2 ; i*i <= n ; i++)
		if ( n%i == 0 ) return false;
	return true;
}

int main()
{
	int p, y;
	cin >> p >> y;
	int i;
	if ( !(y&1) ) y = y-1;
	for ( i = y ; i > p ; i=i-2 )
	{
		if (isPrime(i))
		{
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

bool prime(ll x) {

    for (ll j = 2; j * j <= x; j++)
        if (x % j == 0) return false;
    return true;

}

void solution() {
    ll p, y;
    cin >> p >> y;

    if (p == y) {cout << -1; return;}

    if (p <= 100000) {

        while(y > 1) {
            bool pr = true;
            for (ll j = 2; j <= p; j++) {
                if (y % j == 0) {pr = false; break;}
            }

            if(pr) {cout << y; return;}
            y--;
        }

        cout << -1;

    } else {

        while(y > 1) {
            if (prime(y)) {
                cout << y; return;
            }

            y--;

        }

        cout << -1;

    }

}

int main()
{
    ios_base::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    solution();
    return 0;
}

/*     !ya khoda!     */
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define ld long double

#define pp push
#define po pop()
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()

#define F first
#define S second

#define mkp make_pair
#define pll pair<ll,ll>

#define coutghat(x)      cout<<tolower(x);
#define coutashar(x,d)   cout<<fixed<<setprecision(x)<<(ld)d
#define IOS ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
//#define poow(a,b,M)   b?(poow((a*a)%M,b/2)%M * (b&1?a))%M:1 ;
/*==========================================================================*/
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
//#pragma optimize O3
// 107,109, 211,223, 307, 401,409, 503,509, 601,607, 701,709, 809, 907, 1009
/*==========================================================================*/
const int N=1e4+100 , M=30 , LG=26 , base=2;
const int MOD=1e9+7 , mod=1e9+9;
const ll  INF=1e9   , inf=1e18 ;
ll n,m,p,y , check,ans=-1;
/*==========================================================================*/
int main()
{
	IOS;
	cin>>p>>y;
	n=min((ll)sqrt(y)+1,p);

	for(int i=y ; i>=y-N && i>0 ; i--)
    {
        check=0;
        for(int j=2;j<=n;j++)
        {
            if(i%j==0 || j>=i)
                check=1;
        }
        if(check==0)   ans=max(ans,(ll)i);
    }

	cout<<ans;
	return 0;
}

// Author : deetav
// Happy stalking ! :P
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define ll long long
#define ld long double
#define endl "\n"

const ld PI = acos(-1);
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
const int mod1 = 998244353;
const ll INF = 2e18;

bool isPrime(int n)
{
    if (n <= 1)
        return false;

    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);cerr.tie(nullptr);
    //test
    {
        int p,y;cin>>p>>y;
        for(int i=y;i>p;i--){
            if(isPrime(i)){
                return cout<<i,0;
            }
        }
        cout<<-1;

    }
    return 0;
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

int main() {
  int p,y;

  cin >> p;
  cin >>y;

  int ret=0;
  for(int i=p+1;i<=y;i++) {
    bool pr=false;
    for(int k=2;k*k<=i;k++) {
      if(i%k ==0) pr=true;
    }
    if(!pr) {
      long long ret=i;
      while(ret<=y) {
	ret*=i;
      }
      ret/=i;
      cout << ret<<endl;
      return 0;
    }
  }
  cout << -1 <<endl;
  return 0;

}

#include <iostream>
using namespace std;
//http://codeforces.com/problemset/problem/937/B

/*int main() {
	//http://codeforces.com/problemset/problem/954/C
	int min, max, n, a, b, x, y;
	y = -1;
	cin >> n;
	cin >> a;
	min = max = a;
	while (n > 1) {
		n--;
		b = a;
		cin >> a;
		if (y != -1) {
			if (abs(a - b) == 1) {
				//One is at the begin, other at the end
				if (a + b % (2 * y) == 1) {
					cout << "NO";
					return 0;
				}
			} //Not col-adjacent
			else if (abs(a - b) != y) {
				cout << "NO";
				return 0;
			}
		}
		else if (abs(a - b) != 1) {
			y = abs(a - b);
			if (y == 0 || (min - 1) / y != (max - 1) / y) {
				cout << "NO";
				return 0;
			}
		}
		if (a < min) min = a;
		if (a > max) max = a;
	}
	if (y == -1) y = 1;
	x = (max - 1) / y + 1;
	cout << "YES\n" << x << " " << y;
}*/
int main() {
	int prime[32000] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
	//Max number prime is around 3500
	int n = 14, i, j, p, y, tmp;
	cin >> p >> y;
	//Generate primes up to sqrt y
	if (p > 900000000 && y > 900000000) {
		y = p + 10;
	}
	int mp = sqrt((float)y * 2);
	for (i = 49; ; i+=2) {
		tmp = sqrt((float)i);
		for (j = 0; prime[j] <= tmp; j++)
			if (i % prime[j] == 0)
				break;
		if (prime[j] > tmp) {
			prime[n++] = i;
			if (i > mp) break;
		}
	}
	//From pre-built
	if (p > mp) mp = p;
	if (p > 1 && y % 2 == 0) --y;
	while (y > mp) {
		tmp = sqrt((float)y);
		if (tmp > p) tmp = p;
		for (j = 0; j < n && prime[j] <= tmp; j++)
			if (y % prime[j] == 0)
				break;
		if (prime[j] > tmp) break;
		y -= 2;
	}
	cout << (y > mp ? y : -1);
	//return 0;
}

/*
#include <bits/stdc++.h>
#define ll long long
#define NUM
#define ACC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

set<int>s;
int main()
{
    ACC

    int n;cin >> n;
    for(int i=0;i<n;i++)
    {
       int x; cin >> x;
        if(x!=0)s.insert(x);
    }
    cout << s.size();

    return 0;
}
*/

/*
#include <bits/stdc++.h>
#define ll long long
#define NUM
#define ACC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MAX 1e5
using namespace std;

map<ll,int>prime;

void SieveOfEratosthenes()
{

    for (ll p=2; p*p<=MAX; p++)
    {
        if (prime[p] == false)
        {

            for (ll i=p*p; i<=MAX; i += p)
                prime[i] = true;
        }
    }
}

map<ll,int>vis;
int main()
{
    ACC

    ll p,y;cin >> p>>y;

    for(int i=2;i<=p;i++)
        for(int j=i;j<=y;j+=i)
            vis[j]=1;

    //SieveOfEratosthenes();
    //ll p,y;
    //cin >> p>>y;
    for(ll i=y;i>=p+1;i--)
    {
        if(!vis[i])return cout << i,0;
    }

    cout << -1;

 return 0;
}
*/

#include <bits/stdc++.h>
#define ll long long
#define NUM
#define ACC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MAX 1e5
using namespace std;

int mx;
bool isprime(int x)
{
    int f=0;
    int b=0;
    int t=sqrt(x);
    for(int i=t;i>=1;i--)
    {
        if(i * i == x)
        {
            if(!b)
            {
                b=1;
                mx=i;
            }
            f++;
        }
        else if(x%i == 0)
        {
            if(!b){mx=i;
            b=1;}
            f+=2;
        }
    }
    if(f == 2)return true;
    return false;
}
int main()
{

    ACC

    int p,y;cin>>p>>y;
    for(int i=y;i>p;i--)
    {

        if(isprime(i))return cout << i,0;
        if((i%2!=0)&&mx>p)return cout << i,0;
    }

    cout << -1;

    return 0;
}