p,y=map(int,input().split())

for i in range(y,p,-1):

    c=0
    for j in range(2,(int(i**0.5)+1)):
        if i%j==0 and j<=p:
            c=1
            break
    if c==0:
        print(i)
        exit(0)
print(-1)

from math import sqrt

p, y = list(map(int, input().split()))
yp = int(sqrt(y))

if yp > p:
    yp = p
    if yp % 2 == 0: yp -= 1

if p == 2:
    if y == 2:
        print(-1)
        exit()
    if y % 2 == 0:
        print(y-1)
        exit()
    else:
        print(y)
        exit()

if yp % 2 == 0: yp -= 1

if y % 2 == 0: y -= 1

if yp == 1:
    if y > 2 and y % 2 == 0:
        print(y-1)
        exit()
    if y > p:
        print(y)
        exit()
    else:
        print(-1)
        exit()

while y > p:
    yr = yp
    while yr > 2:
        if y % yr == 0:
            yr -= 2
            break

        elif yr == 3:
            print(y)
            exit()

        elif yr > 3:
            yr -= 2

    y -= 2

print("-1")

def valid(k):
  for i in range(2, k):

      if i*i > k:
          break
      if k % i == 0:
        if i <= p:
            return 0;
        k /= i

  if 1 < k:
    if k <= p:
      return 0
    else:
      return 1

    return 1

answ = 1

p, n = map (int, input ().split ())
for i in range (n, 0, -1):
    if p >= i:
        break
    if valid(i) == 1:
        print(i)
        answ = 0
        break

if answ == 1:
     print(-1)

p, y = map(int, input().split())
for i in range(y, p, -1):
    if all(i % j for j in range(2, min(int(i ** .5), p) + 1)):
        print(i)
        exit()
print(-1)

p,y = map(int, input().split())
from math import sqrt
ans = y
while ans != 1:
    find =True
    if ans <= p:
        ans = 1
        continue
    for i in range(2, min(p+1, int(sqrt(ans))+1)):
        if ans % i == 0:
            find = False
            break
    if find:
        break
    ans -= 1
if ans == 1:
    print(-1)
else:
    print(ans)

import sys

def unhoppable(p, n):
    for d in range(2, n+1):
        if p % d == 0:
            return False
        if d*d > p:
            break
    return True

p, y = map(int, input().split())
for b in range(y, p, -1):
    if unhoppable(b, p):
        print(b)
        sys.exit(0)
print(-1)

from math import sqrt
p,y = map(int,input().split())
def is_prime(n, p):
    if n % 2 == 0 and n > 2:
        return False
    if p == 2: return True
    for x in range(3, min(p, int(sqrt(n))) + 1, 2):
        if n % x == 0:
            return False
    return True

for i in range(y, p,-1):
    if is_prime(i, p):
        print(i)
        exit()
        break
print(-1)

p,y = map(int,input().split())
import math
def is_prime(n,p):
    if n % 2 == 0 and n > 2:
        return False
    if p == 2: return True
    for i in range(3, min(p,int(math.sqrt(n)))+1, 2):
        if n % i == 0:
            return False
    return True
for x in range(y,p,-1):
    if is_prime(x,p):
        print(x)
        break
else:
    print (-1)

import math
p, y = [int(x) for x in input().split()]
def is_prime(n, p):
    if n % 2 == 0 and n > 2:
        return False
    if p == 2: return True
    for x in range(3, min(p, int(math.sqrt(n))) + 1, 2):
        if n % x == 0:
            return False
    return True

for i in range(y, p,-1):
    if is_prime(i, p):
        print(i)
        break
else:
    print(-1)

import math
def CF937B():
    p,x = input("").split(" ")
    p = int(p)
    x = int(x)
    cur = x
    ans = -1
    while cur > p:
        found = False
        for i in range(2,min(int(math.sqrt(cur))+1,p+1)):
            if cur % i == 0:
                found = True
                break
        if (cur % p == 0):
            found = True
        if not found:
            ans = cur
            break
        cur -= 1
    print(ans)

CF937B()

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 26 19:42:02 2018

@author: manish
"""

from math import sqrt
from itertools import count, islice

def isPrime(n):
    if n < 2: return False
    for number in islice(count(2), int(sqrt(n)-1)):
        if not n%number:
            return False
    return True

def chef(d):
    d = list(map(int,d))
    p,y = d[0], d[1]
    ans = -1
    for i in range(y,p,-1 ):
        if isPrime(i) is True:
            ans = i
            return ans
        else:
            z= False
            for j in range(2,p+1):
                if i%j == 0:
                    z=True

                    break
            if z==False:
                ans = i
                return ans
                break
    return ans

def main():
    d= input().split()
    print(chef(d))
main()

from sys import stdin, stdout
ti = lambda : stdin.readline().strip()
ma = lambda fxn, ti : map(fxn, ti.split())
ol = lambda arr : stdout.write(' '.join(str(i) for i in arr) + '\n')
os = lambda i : stdout.write(str(i) + '\n')
olws = lambda arr : stdout.write(''.join(str(i) for i in arr) + '\n')

p, y = ma(int, ti())
ans = -1
import math
while y != p:
	j = 2
	possible = True
	while j <= min(p, int(math.sqrt(y))):
		if y%j == 0:
			possible = False
			break
		j += 1
	if possible:
		os(y)
		exit()

	y -= 1
os(-1)

import math
p,y = map(int,input().split())
ans = -1
"""
if y-p<=1:
    print(-1)
    quit()
"""
while y>p:
    flag= 0
    r = min(math.ceil(math.sqrt(y)),p)
    for j in range(2,r+1):
        if y%j==0:
            flag =1
            break
    if flag == 0:
        ans= y
        break
    y-=1
print(ans)

p, y = map(int, raw_input().split())
z = -1

while y > p:
    t = 0
    i = 2
    while i <= p and i * i <= y:
        if y % i == 0:
            t = 1
            break
        i += 1
    if t == 0:
        z = y
        break
    y -= 1

print z

def fun(x):
    i=2
    while i*i<=x:
        if x%i==0:
            return i
        i+=1
    return x
p,y=map(int,raw_input().split())
while y>p:
    if fun(y)>p:
        print y
        exit()
    y-=1
print -1

p, y = map(int, input().split())
for x in range(y, p, -1):
    if all(x % i for i in range(2, min(int(x ** .5), p) + 1)):
        print(x)
        exit()
print(-1)

# Author : raj1307 - Raj Singh
# Date   : 25.04.2020

from __future__ import division, print_function

import os,sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().strip().split(" "))
def msi(): return map(str,input().strip().split(" "))
def li(): return list(mi())

def dmain():
    sys.setrecursionlimit(100000000)
    threading.stack_size(40960000)
    thread = threading.Thread(target=main)
    thread.start()

#from collections import deque, Counter, OrderedDict,defaultdict
#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
from math import log,sqrt,factorial
#from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
#from decimal import *,threading
#from itertools import permutations
#Copy 2D list  m = [x[:] for x in mark] .. Avoid Using Deepcopy

abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def getKey(item): return item[1]
def sort2(l):return sorted(l, key=getKey,reverse=True)
def d2(n,m,num):return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo (x): return (x and (not(x & (x - 1))) )
def decimalToBinary(n): return bin(n).replace("0b","")
def ntl(n):return [int(i) for i in str(n)]
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(n-r))

def ceil(x,y):
    if x%y==0:
        return x//y
    else:
        return x//y+1

def powerMod(x,y,p):
    res = 1
    x %= p
    while y > 0:
        if y&1:
            res = (res*x)%p
        y = y>>1
        x = (x*x)%p
    return res

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

def read():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')

def main():

    #for _ in range(ii()):

    p,y=mi()

    for i in range(y,1,-1):

        f=1

        for j in range(2,int(sqrt(i))+1):

            if i%j==0:
                if j>p:
                    break
                f=0
                break

        if f:
            if i>p:
                print(i)
            else:
                print(-1)
            break

# region fastio
# template taken from https://github.com/cheran-senthil/PyRival/blob/master/templates/template.py

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    #read()
    main()
    #dmain()

# Comment Read()

def is_prime(n,p):
    if n%2==0:
      return False
    r=int(n**0.5)
    f=3
    while f<=r and f<=p:
        if n%f == 0:
            return False
        f+=2
    return True

p,y=map(int,input().split())

for i in range(y,p,-1):
    if is_prime(i,p):
        print(i)
        break
else:
    print(-1)

p, y = map(int, input().split())
while y > p:
    if y % 2 == 0:
        y -= 1
        continue
    good = 1
    i = 3
    while i * i <= y and i <= p:
        if y % i == 0:
            good = 0
            break
        i += 2
    if good:
        break
    y -= 1
if y == p:
    print(-1)
else:
    print(y)

p,y = map(int,raw_input().split())
for a in xrange(y,p,-1):
	f = 1
	for b in xrange(2,min(int(a**0.5)+1,p+1)):
		if a%b==0:
			f = 0
			break
	if f:
		print a
		exit(0)
print -1

p, m = list(map(int, input().split()))
def ispos(k):
    am = []
    i = 2
    while (i * i <= k):
        if k % i == 0:
            k //= i
            am.append(i)
        else:
            i += 1
    if k != 1:
        am.append(k)
    for i in range(len(am)):
        if am[i] <= p:
            return False
    return True
for i in range(m, max(1, m - 1000), -1):
    if (ispos(i)):
        print(i)
        exit()
print(-1)

p,y=map(int,input().split())

j=y
ans=-1
t=True
while j>p and t:
	for i in range(2,min(int(j**0.5),p)+1):
		if j%i==0:
			break
	else:
		t=False
		ans=j
	j-=1

print(ans)

def prime(x,p):
    for i in xrange(2,min(int(x**0.5),p)+1):
        if x%i==0:
            return False
    return True
p,y=map(int,raw_input().split())
for i in xrange(y,p,-1):
    if prime(i,p):
        print i
        exit()
print -1

import math
"""def Prime_check(x,y):
	for i in range(2,math.sqrt(y)+1):
		if(x%y==0):
			false
"""
def Prime_check(val,y,p):
	i=2
	while((i*i)<=y and i<=p):
		if(val%i==0):
			return(False)
		i=i+1
	return(True)
t=list(map(int,input().split()))
count=-1
if(t[0]==2 and t[0]!=t[1]):
	if(t[1]%2==0):
		print(t[1]-1)
	elif(t[1]==t[0]):
		print(-1)
	else:
		print(t[1])
elif(t[0]==t[1]):
	print(-1)
else:
	for val in range(t[1],t[0],-1):
		if(Prime_check(val,t[1],t[0])):
			print(val)
			count=1
			break
	if(count==-1):
		print(-1)

from functools import reduce

def factors(n):
    return set(reduce(list.__add__,
                      ([i, n // i] for i in range(1, int(pow(n, 0.5) + 1)) if n % i == 0)))

m, p = map(int, raw_input().split())
if p > 400:
    for x in range(p, p - 350, -1):
        tab = sorted(factors(x))
        # print tab
        if tab[1] > m:
            print x
            exit(0)
else:
    for x in range(p, m, -1):
        tab = sorted(factors(x))
        # print tab
        if tab[1] > m:
            print x
            exit(0)
print '-1'
exit(0)

import math

def getPrimes(v):
		d = 2
		gr = int(math.sqrt(v)) + 1
		res = []
		while d <= gr and v > 1:
			if v % d == 0:
				res.append(d)
				while v % d == 0:
					v //= d
			d += 1
		if v > 1:
			res.append(v)
		return res

def solve(p, y):
	x = y
	while x > p:
		pr = getPrimes(x)
		if all(v > p for v in pr):
			return x
		x -= 1
	return -1

p, y = map(int, input().split())
print(solve(p, y))

from math import sqrt

def modpow(a, prime, mod):
    if prime == 1:
        return a % mod
    if mod % 2 == 1:
        return (a * modpow(a, prime - 1, mod)) % mod
    return ((modpow(a, prime/2, mod)) * (modpow(a, prime/2, mod))) % mod

def isPrime(prime):
    for i in range(2, int(sqrt(prime)) + 1):
        if prime % i == 0:
            return False
    return True

def minPrimeDiv(n):
    if isPrime(n):
        return n
    for i in range(2, int(n / 2) + 1):
        if n % i == 0 and isPrime(i):
            return i
    return 0

p, y = list(map(int, input().split()))
ans = y

done = False
s = ''
for i in reversed(range(p+1, y+1)):
    if minPrimeDiv(i) > p:
        s += f' {minPrimeDiv(i)}'
        print(i)
        done = True
        break
if not done:
    print(-1)

#print(isPrime(10))
#print(s)
#print(isPrime(3), isPrime(4), isPrime(5))
#print(modpow(10, 3, 3), modpow(27, 3, 3), modpow(38, 3, 3))

p, y = (int(i) for i in input().split())

def least_divisor(num):
    ans = num
    for i in range(2, int(num ** 0.5 + 1)):
        if num % i == 0:
            ans = i
            break
    return ans

for i in range(y, p, -1):
    if least_divisor(i) > p:
        print(i)
        break

else:
    print(-1)

# -*- coding: utf-8 -*-
"""
Created on Thu Mar  8 21:52:51 2018

@author: Nikita
"""
from math import ceil, sqrt
p, y = map(int, input().split())
while y > p:
    ok = True
    for div in range(2, min(p, ceil(sqrt(y))) + 1):
        if y % div == 0:
            ok = False
            break
    if ok:
        print(y)
        break
    else:
        y -= 1
if y == p:
    print(-1)

import math

def isPrime(n):
    if n % 2 == 0:
        return False

    sqr = int(math.sqrt(n)) + 1

    for divisor in range(3, sqr, 2):
        if n % divisor == 0:
            return False
    return True

def first_factor(n):
    num = 2
    while 1:
        if n % num == 0:
            return num
        num += 1

arr = list(map(int, raw_input().split()))
p = arr[0]
y = arr[1]

while 1:
    if y <= p:
        print -1
        break
    if isPrime(y):
        print y
        break
    elif first_factor(y) <= p:
        y-=1
    else:
        print y
        break

import math

p, y = map(int, raw_input().split())

found = -1
for bn in xrange(y, p, -1):
	prime = True
	for i in xrange(2, min(int(math.sqrt(bn)), p) + 1):
		if bn % i == 0:
			prime = False
			break
	if prime:
		found = bn
		break
print found

p, y = map(int, raw_input().split())

def isPrime(num):
	i=2
	while i <= p and i*i <= num:
		if num%i == 0:
			return False
		i += 1
	return True

ans = -1
for i in xrange(y, p, -1):
	if isPrime(i):
		ans = i
		break
print ans

p,y=map(int,raw_input().split())
h=y
while h>p:
    d=2
    while d<=p and d*d<=h:
        if 0==h%d:
            break
        d+=1
    else:
        print h
        break
    h-=1
else:
    print -1

import sys

def factors(n):
    return set(reduce(list.__add__,
                ([i, n//i] for i in range(1, int(pow(n, 0.5) + 1)) if n % i == 0)))

f = sys.stdin
p, y = [int(i) for i in f.readline().rstrip().split()]

ans = -1
for i in xrange(y, p, -1):
    a = sorted(filter(lambda k: k > 1 and k < i, factors(i)))
    if len(a) == 0 or a[0] > p:
        ans = i
        break
print ans

def main():
    p,y=map(int,input().split())
    i=0
    while i<(10**5)*5:
        if y<=p:
            break
        i+=1
        pr=True
        for w in range(2,p+1):
            if w*w>y:
                break
            if y%w==0:
                pr=False
                break
        if pr:
            print(y)
            return
        y-=1
    print('-1')
main()

p,y=map(int,input().split())
h=y
while h>p:
    d=2
    while d<=p and d*d<=h:
        if 0==h%d:
            break
        d+=1
    else:
        print(h)
        break
    h-=1
else:
    print (-1)

n, m = map(int, raw_input().split())

def prime(a):
	i = 2
	while i <= n and pow(i, 2) <= m:
		if a%i == 0:
			return False
		i += 1
	return True

ans = -1
for i in xrange(m, n, -1):
	if prime(i):
		ans = i
		break
print ans

p,y=map(int,(raw_input().split(' ')))

def vileGrasshoppers(y,p):
    for i in xrange(y,p,-1):
        c=1
        for j in xrange(2,int(i**0.5)+1):
            if i%j==0 and j<=p:
                c=0
                break
        if c:
            return  i
    return  -1

print(vileGrasshoppers(y,p))

#http://codeforces.com/contest/937/problem/B

import math
p, y = input().split()
p = int(p)
y = int(y)
for i in range(y, p, -1):
    for d in range(2, min(int(math.sqrt(i))+1, p+1)):
        if i % d == 0:
            break
    else:
        print(i)
        break
else:
    print(-1)

from math import sqrt

def solve(p, y):
    for i in xrange(300):
        cur = y - i
        if cur == p:
            return -1
        x = 2
        bad = False
        while x*x <= cur and x <= p:
            if (cur % x) == 0:
                bad = True
                break
            x += 1
        if not bad:
            return cur

    return -1

def main():
    print solve(*map(int, raw_input().split()))

if __name__ == "__main__":
    main()

def isdiv(i,p):
    upto = min(p,int(i**0.5)+1)
    for j in xrange(2,upto+1):
        if i%j==0:
            return True
    return False

p,y = map(int,raw_input().split())

ans = -1
for i in xrange(y,p,-1):
    if not isdiv(i,p):
        ans = i
        break
print ans

def minf(n):
    i = 2
    while i ** 2 <= n:
        if n % i == 0:
            return i
        i += 1
    return n
p, y = map(int, input().split())
for i in range(y, p, -1):
    if minf(i) > p:
        print(i)
        exit()
print(-1)

p, y = map(int, input().split())
while y > p:
    if y % 2 == 0:
        y -= 1
        continue
    good = 1
    i = 3
    while i * i <= y and i <= p:
        if y % i == 0:
            good = 0
            break
        i += 2
    if good:
        break
    y -= 1
if y == p:
    print(-1)
else:
    print(y)

import math

def check(n, top):
    for x in range(2, top+1):
        if n % x == 0:
            return False
    return True

if __name__ == '__main__':
    p, y = input().split()
    p = int(p)
    y = int(y)

    m = min(math.floor(math.sqrt(y)),p)

    cur = y
    while cur > p:
        if check(cur, m):
            print(cur)
            exit()
        cur -= 1

    print(-1)

n,h = map(int,input().split())
for i in range(h,n,-1):
    if all(i%j for j in range(2,min(int(i**.5),n)+1)):print(i);exit()
print(-1)

import math

p, y = [int(c) for c in input().split(" ")]

def p1(p, y):
    primelist = [2]
    for i in range(3, p + 1, 2):
        tempstatus = True
        for pp in primelist:
            if i % pp == 0:
                tempstatus = False
                break
        if tempstatus:
            primelist.append(i)
    ans = -1
    for i in range(y, p, -1):
        tempstatus = True
        for pp in primelist:
            if i % pp == 0:
                tempstatus = False
                break
        if tempstatus:
            ans = i
            break

    #print(primelist[:100])
    return ans

def p2(p, y):
    primelist = [2]
    for i in range(3, min(int(math.sqrt(y)), p) + 1, 2):
        tempstatus = True
        for pp in primelist:
            if i % pp == 0:
                tempstatus = False
                break
        if tempstatus:
            primelist.append(i)
    ans = -1
    for i in range(y, p, -1):
        tempstatus = True
        for pp in primelist:
            if i % pp == 0:
                tempstatus = False
                break
        if tempstatus:
            ans = i
            break

    # print(primelist[:100])
    return ans

print(p2(p, y))

from math import ceil
p,y=map(int,input().split())
for i in range(y, p, -1):
    c=False
    for j in range(2, ceil(i**0.5)+1):
        if i%j==0 and j <= p:
            c=True
            break
    if c:
        continue
    print(i)
    exit()
print(-1)

def prime(x,p):
    z=int(x**0.5)+1
    for i in range(2,z):
        if x%i==0 and i<=p:
            return False
    return True
p,y=map(int,input().split())
flag=0
while flag==0 and y>p:
    if prime(y,p):
        flag=1
        break
    y-=1
if flag==1:
    print(y)
else:
    print(-1)

import math,sys
from collections import Counter, defaultdict
from sys import stdin, stdout
#input = stdin.readline
lili=lambda:list(map(int,sys.stdin.readlines()))
li = lambda:list(map(int,input().split()))

def checkprime(a):
    for i in range(2, int(a**0.5)+1):
        if a%i == 0 and i <= z[0]:
            return False
    return True
z = li()
for i in range(z[1], z[0], -1):
    if checkprime(i):
        print(i)
        exit()
print(-1)

def mindiv(i,p):
    cnt=p+1
    j=2
    while(j*j<=i):
        if(i%j!=0):
            j=j+1
            continue
        else:
            cnt=min(cnt,j)
            cnt=min(cnt,i//j)
            j=j+1
    return cnt
p,y=[int(p) for p in input().split()]
for i in range(y,p,-1):
    if(mindiv(i,p)<=p):
        continue
    else:
        print(i)
        exit()
print(-1)

import math as M

p, y = [int(x) for x in input().split()]

lim = min(int(M.sqrt(y)) + 1, p) + 1
primes = []

for n in range(2, lim):
    for m in range(2, int(M.sqrt(n)) + 1):
        if n % m == 0:
            break
    else:
        primes.append(n)

for k in range(y, p, -1):
    for m in primes:
        if k % m == 0:
            break
    else:
        print(k)
        break
else:
    print(-1)

#
# arr = [True] * (y + 1)
# for i in range(2, min(M.ceil(M.sqrt(y)), p) + 2):
#     if arr[i]:
#         k = i
#         while k < y + 1:
#             arr[k] = False
#             k += i
#
# # print(arr)
# for k in range(y, 1, -1):
#     if arr[k]:
#         print(k)
#         break
# else:
#     print(-1)

import math

p, y = map(int, input().split())

def isPrime(p,n):
    i = 2
    while i <= math.sqrt(n) and i <= p:
        if n%i == 0:
            return False
        i += 1
    return True

i = y
ans = -1
while i > p:
    if isPrime(p,i):
        ans = i
        break
    i -= 1

print(ans)

import math
from sys import stdin
string=stdin.readline().strip().split()
p=int(string[0])
y=int(string[1])
def findmf(number):
    factor=number
    for i in range(2,math.floor(math.sqrt(number))+1):

        if number%i==0:
            factor=i

            break
    return factor
while True:
    if p<findmf(y):

        break
    elif y>p:

        y-=1
    else:
        y=-1

        break
print(y)

import math
p,y=map(int,input().split())
def check(a):
    for i in range(2,min(int(math.sqrt(a)),p)+1):
        if a%i==0:
            return False
    return True
while y>p:
    if check(y):
        print(y)
        exit(0)
    y=y-1
print(-1)

p,y=list(map(int,input().split()))
t=min(p,int(y**.5)+2)
for i in range(y,p,-1):
  while t*t>i:t-=1
  if not any(i%x==0 for x in range(2,t+1)):
    print(i)
    exit(0)
print(-1)

import math

p, y = map(int, input().split())

if y % 2 == 0:
    y -= 1
for i in range(y, p, -2):
    ok = True
    ans = i
    for d in range(3, int(math.sqrt(i)) + 1):
        if i % d == 0:
            if d <= p:
                ok = False
            break
    if ok:
        print(ans)
        exit()
print(-1)

def mlt(): return map(int, input().split())

x, y = mlt()

def mn(x):
    n = 2
    if x % 2 == 0:
        return 2

    n = 3
    while n*n <= x:
        if x % n == 0:
            return n
        n += 2

    return x

while y > x:
    if mn(y) > x:
        print(y)
        exit(0)
    y -= 1

print(-1)

import math
import sys

def is_prime(n, p):
    if n % 2 == 0 and n > 2:
        return False
    for i in range(3, int(math.sqrt(n)) + 1, 2):
        if i > p: break
        if n % i == 0:
            return False
    return True

def main():
    p, y = map(int, sys.stdin.readline().split())

    highest = y
    if y % 2 == 0:
        highest -= 1
    while highest > p:
        if is_prime(highest, p):
            print(highest)
            return
        highest -= 2

    print(-1)

if __name__ == '__main__':
    main()

p, y = [int(x) for x in input().split()]
res = -1
for i in range(y, p, -1):
    flag = True
    for a in range(2, min(p+1, int(i**0.5)+1)):
        if i % a == 0:
            flag = False
            break
    if flag:
        res = i
        break
print(res)

p, y = map(int, input().split())
for x in range(y, p, -1):
    if all(x % i for i in range(2, min(int(x ** .5), p) + 1)):
        print(x)
        exit()
print(-1)

p, y = map(int, input().split())
for number in range(y, p, -1):
    for i in range(2, min(int(number ** 0.5) + 2, p + 1)):
        if number % i == 0:
            break
    else:
        print(number)
        break
else:
    print(-1)

p, n = (int(x) for x in input().split())
flag = False
for i in range(n, p, -1):
    flag = True
    # print(i)
    for j in range(2, min(int(n ** 0.5), p) + 1):
        if i % j == 0:
            flag = False
            break
    if flag:
        print(i)
        break
if not flag:
    print(-1)

p,y= [int(x) for x in input().split()]
import math as m

for i in range(y, p, -1):
    for d in range(2, min( int(m.sqrt(i))+1, p+1 )):
        if i % d ==0:
            break
    else:
        print(i)
        break
else:
    print(-1)

import math
import sys
import math
def div(p,n) :
    m=10**10
    for i in range(2, int(math.sqrt(n) + 1)) :
        if (n % i == 0) :
            if (n / i == i and i<m) :
                m=i
            else :
                if i<m:
                    m=i
                if n//i <m:
                    m=int(n//i)
    if m>p:
        return 1
    else:
        return 0
p,y=map(int,input().split())
ctr=0
while(y>p and ctr<=300):
    a=div(p,y)
    if a!=0:
        print(y)
        sys.exit(0)
    y-=1
    ctr+=1
print(-1)

P, Y = [int(_) for _ in input().split()]
if Y % 2 == 0:
    Y -= 1
while Y > P:
    f = 1
    for i in range(3, min(int(Y**0.5), P) + 1, 2):
        if Y % i == 0:
            f = 0
            continue
    if f:
        print(Y)
        exit()
    Y -= 2
print(-1)

import sys
def fun(n,p,y):
    i=2
    while i<=p and i**2<=y:
        if n%i==0:
            return False
        i+=1

    return True

p,y=map(int,input().split())
ans=-1
for i in range(y,p,-1):
    if fun(i,p,y):
        print(i)
        sys.exit()
print(-1)

p,y = map(int, input().split())

for x in range(y, p, -1):
    if all(x%i for i in range(2,min(p, int(x**0.5))+1)):
        print(x)
        exit()

print (-1)

import math

p,y = [int(x) for x in input().split()]

def check(x):
	mx = int(math.sqrt(x)) + 1
	for i in range(2,min(p,mx) + 1):
		if x % i == 0:
			return False
	return True

ans = -1

for x in range(max(p + 1,y - 300),y + 1):
	if check(x):
		ans = x

print(ans)

from math import sqrt

p, y = [int(i) for i in input().split()]
for i in range(y, p, -1):
    if all(i % j for j in range(2, min(p, int(sqrt(i))) + 1)):
        print(i)
        exit()
print(-1)

p, y = map(int, input().split())

mx = 33000

v = [False]*mx
for x in range(2, mx):
    if not v[x]:
        for i in range(x*x, mx, x):
            v[i] = True
primes = [i for i, _ in enumerate(v) if not _ and i>1]
fail = True
for v in range(y, p, -1):
    fail = False
    for pr in primes:
        if pr <= p and v%pr == 0:
            fail = True
        elif pr > p: break
    if not fail:
        print(v)
        break

if fail:
    print(-1)

p,y = map(int,input().split())
for x in range(y,p,-1):
    if all(x%i for i in range(2,min(p,int(x**.5))+1)):
        print(x)
        exit()
print(-1)

p, y = map(int, input().split())
for i in range(y, p, -1):
	# print (min(p, int(i ** 0.5 + 1)))
	if all(i % j != 0 for j in range(2, min(p, int(i ** 0.5 + 1)) + 1)):
		print (i)
		exit()
print (-1)

p,y = list(map(int, input().split()))
flag = False
ans = -1

for x in range(y,p,-1):
    flag = False
    for i in range(2, min(p, int(x ** 0.5)) + 1):
        if x%i==0:
            flag = True
            break
    if not flag:
        ans = x
        break

if not flag:
    print(ans)
else:
    print(-1)

p,y = map(int, input().split())

def is_div(a, m):
    if a % 2 == 0 or a % 3 == 0:
        return True
    i = 5
    m = min(m, a ** 0.5)
    while i < m:
        if a % i == 0 or (i + 2 < m and a % (i + 2) == 0):
            return True
        i += 6
    return False

for i in range(y - int(y % 2 == 0), p, -2):
    if not is_div(i, p):
        print(i)
        exit(0)

print(-1)

n,p=input().split()
n,p=int(p),int(n)
for i in range(n,p,-1):
	for j in range(2,p+1):
		if j*j>i or i%j==0:
			break
	if j==p or j*j>i:
		print(i)
		exit(0)
print(-1)

from math import ceil
p,y=map(int,input().split())
for i in range(y, p, -1):
    c=False
    for j in range(2, ceil(i**0.5)+1):
        if i%j==0:
            c=True
            break
    if c:
        continue
    print(i)
    exit()
print(-1)

import math
"""def Prime_check(x,y):
	for i in range(2,math.sqrt(y)+1):
		if(x%y==0):
			false
"""
def Prime_check(val,y):
	for i in range(2,int(math.sqrt(val))+1):
		if(i>y):
			break
		elif(val%i==0):
			return(False)
	return(True)
t=list(map(int,input().split()))
count=-1
if(t[0]==2 and t[0]!=t[1]):
	if(t[1]%2==0):
		print(t[1]-1)
	elif(t[1]==t[0]):
		print(-1)
	else:
		print(t[1])
elif(t[0]==t[1]):
	print(-1)
else:
	for val in range(t[1],t[0],-1):
		if(Prime_check(val,t[1])):
			print(val)
			count=1
			break
	if(count==-1):
		print(-1)

import math
"""def Prime_check(x,y):
	for i in range(2,math.sqrt(y)+1):
		if(x%y==0):
			false
"""
def Prime_check(val,y):
	for i in range(2,int(math.sqrt(val))+1):
		if(i>y):
			break
		elif(val%i==0):
			return(False)
	return(True)
t=list(map(int,input().split()))
count=-1
if(t[0]==2):
	if(t[1]%2==0):
		print(t[1]-1)
	elif(t[1]==t[0]):
		print(-1)
	else:
		print(t[1])
elif(t[0]==t[1]):
	print(-1)
else:
	for val in range(t[1],t[0],-1):
		if(Prime_check(val,t[1])):
			print(val)
			count=1
			break
	if(count==-1):
		print(-1)

import math

def is_prime(n):
    if n == 0 or n == 1: return False
    for x in range(2, int(math.sqrt(n))+1):
        if n % x == 0:
            return False
    return True

if __name__ == '__main__':
    p, y = input().split()
    p = int(p)
    y = int(y)

    cur = y
    while cur > p:
        if is_prime(cur):
            print(cur)
            exit()
        cur -= 1

    print(-1)

p,y=map(int,input().split())
from math import sqrt as S
f=-1
for i in range(y,p,-1):
    if all(i%j for j in range(2,min(p,int(S(i))+1))):
        f=1
        print(i)
        break
if f==-1:
    print(f)

p,y = map(int,input().split())

for x in range(y,p,-1):
	# print(x)
	# check
	flag = True
	for i in range(2,min(p,int(x**0.5)+1)):
		if x%i == 0:
			flag = False
			break
	if flag:
		print(x)
		exit()

print(-1)

def prime_number(x):
    if x <= 1:
        return False
    i = 2
    while i * i <= x:
        if(x % i == 0):
            return False
        i += 1
    return True

p, y = map(int,input().split())
flag = -1
num_list = []

for i in range(p,y+1):
    num_list.append(i)
num_list.reverse()

for i in num_list:
    if(prime_number(i) and i != p):
        print(i)
        flag = 1
        break
if flag != 1:
    print("-1")

p,y = map(int,input().split())
for i in range(y,p,-1):
    check = True
    for j in range(2,round(p ** 0.5) + 1):
        if i % j == 0:
            check = False
            break
    if check:
        print(i)
        exit()
print(-1)

n,h = map(int,input().split())

l = [0,0]+[1]*(h-1)

for i in range(2,n+1):
    if l[i]:
        j = i
        while j<=h:l[j]=0;j+=j

ans = -1

for i in range(h,1,-1):
    if l[i]:ans=i;break

print(ans)

p, y = map(int, input().split())
for i in range(y, p, -1):
	# print ((int(i ** 0.5)))
	if all(i % j != 0 for j in range(2, min(p, int(i ** 0.5) + 1))):
		print (i)
		exit()
print (-1)

import math

p, y = [int(c) for c in input().split(" ")]
primelist = [2]

for i in range(3, min(int(math.sqrt(y)), p) + 1, 2):
    tempstatus = True
    for p in primelist:
        if i % p == 0:
            tempstatus = False
            break
    if tempstatus:
        primelist.append(i)

ans = -1
for i in range(y, p, -1):
    tempstatus = True
    for p in primelist:
        if i % p == 0:
            tempstatus = False
            break
    if tempstatus:
        ans = i
        break

# print(primelist[:100])
print(ans)

import sys

def unhoppable(p, n):
    for d in range(2, n+1):
        if p % d == 0:
            return False
        if d*d > p:
            break
    return True

p, y = map(int, input().split())
for b in range(y, p, -1):
    if unhoppable(b, y):
        print(b)
        sys.exit(0)
print(-1)

p,y = map(int,raw_input().split())
x = y/p+1
if(x<=2):
	print -1
else:
	print x

from sys import stdin, stdout
ti = lambda : stdin.readline().strip()
ma = lambda fxn, ti : map(fxn, ti.split())
ol = lambda arr : stdout.write(' '.join(str(i) for i in arr) + '\n')
os = lambda i : stdout.write(str(i) + '\n')
olws = lambda arr : stdout.write(''.join(str(i) for i in arr) + '\n')

p, y = ma(int, ti())
ans = -1
while y != p:
	j = 2
	possible = True
	while j*j <= y:
		if y%j == 0:
			possible = False
			break
		j += 1
	if possible:
		os(y)
		exit()

	y -= 1
os(-1)

p,y = map(int,raw_input().split())
for a in xrange(y,p,-1):
	f = 1
	for b in xrange(2,min(int(a**0.5)+1,p)):
		if a%b==0:
			f = 0
			break
	if f:
		print a
		exit(0)
print -1

import math
def fact(n):
    while n % 2 == 0:
        s.add(2)
        n = n / 2
    for i in range(3,int(math.sqrt(n))+1,2):
        while n % i== 0:
            s.add(i)
            n = n / i
    if n > 2:
        s.add(n)
input=__import__('sys').stdin.readline
p,y = map(int,input().split())
s=set()
mm = y-max(y-200,p)
for i in range(mm):
    fact(y)
    l=sorted(s)
#    print(l)
    if int(l[0])>p:
        print(y)
        exit()
    s = set()
    y-=1
print(-1)

n,y = map(int,input().split())
l=[]
i=max(n+1,y-n)
while i<y:
	l.append(i)
	i+=1
if len(l)==0:
	print(-1)
else:
	for i in l:
		if i%n==0:
			l.remove(i)
	print(max(l))

from collections import deque
from math import ceil,sqrt
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc="abcdefghijklmnopqrstuvwxyz"
p,y=mi()
def isPrime(n) : # Check Prime Number or not
    for i in range(2,p+1):
        if(n%i==0):
            return 0
        if(i*i>n):
            break
    return 1

f=0
for i in range(y-1,p,-1):
    if(isPrime(i)):
        print(i)
        f=1
        break
if(f==0):
    print("-1")

p, y = list(map(int , input().split()))

if y%2 == 0:
    y -= 1

for cur in range(y, p, -2):
    maxp = min(p, int(y**0.5)+1)
    for k in range(3,maxp):
        if cur%k == 0:
            # print(cur, 'does not fit due to', k)
            break
    else:
        print(cur)
        exit()

print(-1)

def f(n):
    i=2
    while i*i<=n:
        if n%i==0:
            return False
        i+=1
    return True
p,y=map(int,input().split())
if p>10000:
    i=y
    while not f(i):
        if i==p:
            print(-1)
            exit()
        i-=1
    print(i)
else:
    for i in range(y,p,-1):
        for j in range(2,p+1):
            if i%j==0:
                break
        else:
            print(i)
            break
    else:
        print(-1)

from math import factorial
p, y = [int(x) for x in input().split()]
r = factorial(p)
if r - 1 > y:
    print(-1)
else:
    print(r - 1)

import math
arr=[]
p,y=(map(int,input().split()))
for i in range(p+1,y):
    #print(math.floor(y/i)*2)
    if math.floor(y/i)*2!=i:
        arr.append(i)
if arr:
     print(max(arr))
else:
     print(-1)

import math as M

p, y = [int(x) for x in input().split()]

lim = min(int(M.sqrt(y)) + 1, p) + 1
primes = []

for n in range(2, lim):
    for m in range(2, int(M.sqrt(n)) + 1):
        if n % m == 0:
            break
    else:
        primes.append(n)

for k in range(y, 1, -1):
    for m in primes:
        if k % m == 0:
            break
    else:
        print(k)
        break
else:
    print(-1)
#
# arr = [True] * (y + 1)
# for i in range(2, min(M.ceil(M.sqrt(y)), p) + 2):
#     if arr[i]:
#         k = i
#         while k < y + 1:
#             arr[k] = False
#             k += i
#
# # print(arr)
# for k in range(y, 1, -1):
#     if arr[k]:
#         print(k)
#         break
# else:
#     print(-1)

import math
p,y = map(int,input().split())
def isprime(a):
    for i in range(2,math.ceil(math.sqrt(a))):
        if a%i==0:
            return False
    return True
if y-p<=1:
    print(-1)
    quit()
for i in range(y-1,p,-1):
    if isprime(i):
        print(i)
        break

from sys import stdin
def is_prime(n):
    if n <= 1:
        return False
    if n <= 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i = i + 6
    return True

x, y = map(int, stdin.readline().rstrip().split(" "))

if not y%2:
    start =y-1
else:
    start = y
c = 0
for i in range(start, x, -2):
    if is_prime(i):
        c = i
        break

if c == 0:
    print(-1)
else:
    for i in range(start, y-y%c, - 2):
        check = False
        for j in range(3,x,2):
            if i%j==0:
                check=True
                break
        if not check:
            c = i
            break
    print(c)

# -*- coding: utf-8 -*-
"""
Created on Thu Mar  8 21:52:51 2018

@author: Nikita
"""
from math import ceil, sqrt
p, y = map(int, input().split())
y_copy = y
while y >= y_copy - 300 and y > p:
    ok = True
    for div in range(2, min(p, ceil(sqrt(y)) + 1)):
        if y % div == 0:
            ok = False
            break
    if ok:
        print(y)
        break
    else:
        y -= 1
if y == y_copy - 301 or y == p:
    print(-1)

from sys import stdin
def is_prime(n):
    if n <= 1:
        return False
    if n <= 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i = i + 6
    return True

x, y = map(int, stdin.readline().rstrip().split(" "))

f = 0

for i in range(x+1, y+1):
    if is_prime(i):
        f = i
        break

if f == 0:
    print(-1)
else:
    print(y - y%f)

p, y = map(int, input().split())
for i in range(y, p, -1):
    if all(i % j != 0 for j in range(2, min(p, i**0.5 + 2))):
        print(i)
        exit()

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 25 21:50:26 2018

@author: manish
"""

d = ['3','6']
import math

def chef(d):
    d = list(map(int,d))
    p,y = d[0], d[1]

    #    list1 = []
    #    for i in range(2,p+1):
    #        list1.append(i)
    m =[]

    for num in range(p+1,y+1):
        if all(num%i!=0 for i in range(2,int(math.sqrt(num))+1)):
            m.append(num)
    if m!=[]:
        ans = m[-1]
    else:
        ans = -1
#    ans = -1
#
#    for i in tqdm.tqdm(range(y,p, -1)):
##        print(i)
#        z=True
#        for j  in m:
#            if i%j == 0:
#                z = False
#                break
#        if z==True:
#
#            ans = i
#            return ans
    return ans
#    #for i in range(2, p+1):
#    #    for j in range(1, int(y/i)+1):
#    ##            print(list1[i+1:])
#    #        if j*i in m :
#    ##            or j*list1[i] in list1[i+1:]:
#    #            break
#    #        m.append(j*i)
#    m.sort()
#    #    if m[-1] < y:
#    #        print('yes')
#    #        print(m[-1]+1)
#    #        for i in range(m[-1]+1, y+1):
#    #            print(i)
#    #            m.append(i)
#    #    m.sort(reverse = True)
#    #    print(m)
#    #    print(m)
#    ans = -1
#    for i in range(len(m)-1, 0, -1):
#        if m[i]<y and y not in m:
#            ans = y
#            break
#        if m[i-1] != m[i]-1:
#            ans = m[i]-1
#            break
#    return ans
#
def main():

    d= input().split()

    print(chef(d))

main()

def main():
    p,y=map(int,input().split())
    q=False
    if p*p>y:
        q=True
    i=0
    while i<(10**7)*5:
        if y<=p:
            break
        i+=1
        if q:
            w=2
            pr=True
            while w*w<=y:
                if y%w==0:
                    pr=False
                    break
                w+=1
            if pr:
                print(y)
                return
        else:
            pr=True
            for w in range(2,p):
                if y%w==0:
                    pr=False
                    break
            if pr:
                print(y)
                return
        y-=1
    print('-1')
main()

def min_divider(n):
	ans = 2
	tc = n ** 0.5 // 1
	while n % ans != 0 and ans < tc:
		ans += 1
	if ans == tc and tc * tc != n:
	    return n
	return ans

p, y = map(int, input().split())
while min_divider(y) <= p and y > p:
	y -= 1
if y == p:
	print(-1)
else:
	print(y)

p,y = map(int,input().split())
for i in range(y,p,-1):
    check = True
    for j in range(2,round(p ** 0.5) + 2):
        if i % j == 0:
            check = False
            break
    if check:
        print(i)
        exit()
print(-1)

from math import sqrt
p, y = [int(x) for x in input().split()]

def isprime(n):
    if n == 2:
        return False
    for x in range(2, min(int(sqrt(n)) + 1, p)):
        if n % x == 0:
            return False
    return True

for i in range(y, p,-1):
    if isprime(i):
        print(i)
        exit()
print(-1)

from math import sqrt

p, y = list(map(int, input().split()))

yp = int(sqrt(y))

if p == 2 and y == 2:
    print(-1)
    exit()

if yp % 2 == 0: yp += 1

if y % 2 == 0: y -= 1

if yp == 1:
    if y > 2 and y % 2 == 0:
        print(y-1)
        exit()
    else:
        print(y)
        exit()

while y > p:
    yr = yp
    while yr > 2:
        if y % yr == 0:
            yr -= 2
            break

        elif yr == 3:
            print(y)
            exit()

        elif yr > 3:
            yr -= 2

    y -= 2

print("-1")

p,y=map(int,input().split())
from math import sqrt as S
f=-1
for i in range(y,p,-1):
    if all(i%j for j in range(2,min(p,int(S(i))+1))):
        f=1
        print(i)
        break
if f==-1:
    print(f)

p,y = list(map(int, input().split()))
flag = False
ans = 0

for x in range(y,p,-1):
    flag = False
    for i in range(2,p+1):
        if x%i==0:
            flag = True
            break
    if not flag:
        ans = x
        break

if not flag:
    print(ans)
else:
    print(-1)

import math

p, y = [int(c) for c in input().split(" ")]
primelist = [2]

for i in range(11, min(round(math.sqrt(y)), p) + 1, 2):
    tempstatus = True
    for p in primelist:
        if i % p == 0:
            tempstatus = False
            break
    if tempstatus:
        primelist.append(i)

ans = -1
for i in range(y, p, -1):
    tempstatus = True
    for p in primelist:
        if i % p == 0:
            tempstatus = False
            break

    if tempstatus:
        ans = i
        break

print(ans)

from math import factorial
p, y = [int(x) for x in input().split()]
r = factorial(p)
if r - 1 > y:
    print(-1)
else:
    print(r - 1)

from math import sqrt
p, y = [int(x) for x in input().split()]

def isprime(n):
    if n % 2 == 0 and n > 2:
        return False
    if p == 2:
        return True
    for x in range(3, min(int(sqrt(n)) + 1, p), 2):
        if n % x == 0:
            return False
    return True

for i in range(y, p,-1):
    if isprime(i):
        print(i)
        exit()
print(-1)

# -*- coding: utf-8 -*-
"""
Created on Wed Mar  7 09:39:50 2018

@author: wangjun
"""
import math

def Grasshopper(ng,nb):

    if nb%2 ==0 :
        nb=nb-1
    if ng > 3:
        nng = math.floor( ng ** 0.5 )
    else:
        nng=ng
    for branch in range(nb,ng,-2):
        flag =True
        for hopper in range(3,nng,2):
            if branch % hopper == 0:
                flag = False
                break
        if flag==True :
            return branch
    return -1

def hello():
    """Print "Hello World" and return None"""
    ar = list(map(int, input().strip().split(' ')))

    result=Grasshopper(ar[0],ar[1])
    print(result)
# main program starts here
hello()

p, y = map(int, input().split())
ex = False
first = False
for i in range(301):
    j = 2
    first = False
    while j ** 2 <= y:
        if y % j == 0:
            first = True
            if j > p:
                ex = True
        j += 1
    if not first:
        if y > p:
            ex = True
    if ex:
        break
    y -= 1
if ex:
    print(y)
else:
    print(-1)

def main():
    P, Y = map(int, input().split())

    branch = [0] * (Y + 1)
    for i in range(2, P + 1):
        while i <= Y:
            branch[i] = 1
            i *= 2

    if all(branch[2:]):
        print(-1)
    else:
        print(Y - branch[::-1].index(0))

main()

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 25 21:50:26 2018

@author: manish
"""

d = ['3','6']

def chef(d):
    d = list(map(int,d))
    p,y = d[0], d[1]

    list1 = []
    for i in range(2,p+1):
        list1.append(i)
    m = []

    for i in range(0, len(list1)):
        for j in range(1, int(y/list1[i])+1):
#            print(list1[i+1:])
            if j*list1[i] in m or j*list1[i] in list1[i+1:]:
                break
            m.append(j*list1[i])
#    m.sort()
#    if m[-1] < y:
#        print('yes')
#        print(m[-1]+1)
#        for i in range(m[-1]+1, y+1):
#            print(i)
#            m.append(i)
    m.sort(reverse = True)
#    print(m)
#    print(m)
    ans = -1
    for i in range(0, len(m)-1):
        if m[i]<y and y not in m:
            ans = y
            break
        if m[i+1] != m[i]-1:
            ans = m[i]-1
            break
    return ans

def main():

    d= input().split()

    print(chef(d))

main()

'''input
3 6
'''
from math import sqrt
p=[]
pr=[1]*(10**5)
pr[1]=0
pr[0]=0

for i in range(4,10**5,2):
    pr[i]=0
for i in range(3,400,2):
    if pr[i]:
        for j in range(i*i,10**5,2*i):
            pr[j]==0
for i in range(10**5):
    if pr[i]:
        p.append(i)
def prime(n):
    sq=int(sqrt(n))+1
    for i in np:
        if i>sq:
            return True
        if n%i==0:
            return False
    return True
ppp,n=[int(x) for x in raw_input().split()]
sq=int(sqrt(n))+1
pppp=ppp
ppp=max(ppp,sq)
np=[]
for i in p:
    if i<sq:
        np.append(i)
    else:
        break
lp=n
if lp%2==0:
    lp-=1
ans=-1
while  lp>pppp:
    if prime(lp):
        ans=lp
        break
    lp-=2

print ans

import math
p,y=map(int,input().split())
def check(a):
    for i in range(2,int(math.sqrt(a))+1):
        if a%i==0:
            return False
    return True
while y>p:
    if check(y):
        print(y)
        exit(0)
    y=y-1
print(-1)

p, y = map(int, input().split())
for x in range(y - (y & 1 ^ 1), p, -2):
    if x & 1 and all(x % i for i in range(3, min(int(x ** .5) + 2, p), 2)):
        print(x)
        exit()
print(-1)

p, y = map(int, input().split())
for i in range(y, p, -1):
    if all(i % j for j in range(2, min(int(i ** .5), p + 1))):
        print(i)
        exit()
print(-1)

n,p=input().split()
n,p=int(p),int(n)
for i in range(n,p,-1):
	for j in range(2,p+1):
		if j*j>i or i%j==0:
			break
	if j==p or j*j>i:
		print(i)
		exit(0)
print(-1)

import sys

def is_prime(n):
    if n == 1:
        return False
    i = 2
    while i*i <= n:
        if n % i == 0:
            return False
        i += 1
    return True

f = sys.stdin
NMAX = 1e9
p, y = [int(i) for i in f.readline().rstrip().split()]
if p == y:
    print -1
ans = -1
for i in xrange(p + 1, y + 1):
    if is_prime(i):
        ans = i
        break
print ans

def chek(a,p) :
    i=2
    p=min(p,int(pow(i,0.5))+1)
    while (i<=p) :
        if a%i==0 :
            return False
        i+=1
    return True
b,a=map(int,input().split())
while (a>b) :
    if chek(a,b) :
        print(a)
        exit()
    a-=1

print(-1)

from math import sqrt
p, y = [int(x) for x in input().split()]

def isprime(n):
    if n == 2:
        return False
    for x in range(2, int(sqrt(n)) + 1):
        if n % x == 0:
            return False
    return True

for i in range(y, p,-1):
    if isprime(i):
        print(i)
        exit()
print(-1)

def SieveOfEratosthenes(ps,n):

    prime = [True for i in range(n+1)]
    p = 2
    while (p * p <= n):

        # If prime[p] is not changed, then it is a prime
        if (prime[p] == True):

            # Update all multiples of p
            for i in range(p * 2, n+1, p):
                prime[i] = False
        p += 1
    count=-1
    for p in range(n-1, 2,-1):
        if (prime[p] and p>ps):
        	count=p
    print(count)
t=list(map(int,input().split()))
if(t[0]==2):
	if(t[1]%2==0 and t[0]!=t[1]):
		print(t[1]-1)
	elif(t[1]==t[0]):
		print(-1)
	else:
		print(t[1])
else:
	SieveOfEratosthenes(t[0],t[1])

import math,sys
from collections import Counter, defaultdict
from sys import stdin, stdout
#input = stdin.readline
lili=lambda:list(map(int,sys.stdin.readlines()))
li = lambda:list(map(int,input().split()))

def checkprime(a):
    if a%2:
        return True
    for i in range(2,min(p,int(a**0.5)+1)):
        if a%i == 0:
            return False
    return True
p, y = map(int, input().split())
for i in range(y, p, -1):
    if checkprime(i):
        print(i)
        exit()
print(-1)

import math

p, y = map(int, input().split())

def isPrime(p,n):
    i = 2
    while i <= math.sqrt(n) and i < p:
        if n%i == 0:
            return False
        i += 1
    return True

i = y
ans = -1
while i > p:
    if isPrime(p,i):
        ans = i
        break
    i -= 1

print(ans)

from math import ceil
p,y=map(int,input().split())
for i in range(y, p, -1):
    c=False
    for j in range(2, ceil(i**0.5)+1):
        if i%j==0:
            c=True
            break
    if c:
        continue
    print(i)
    exit()
print(-1)

import math
import sys

def is_prime(n, p):
    if n % 2 == 0 and n > 2:
        return False
    for i in range(3, int(math.sqrt(n)) + 1, 2):
        if i > p: break
        if n % i == 0:
            return False
    return True

def main():
    p, y = map(int, sys.stdin.readline().split())

    highest = y
    if y % 2 == 0:
        highest -= 1
    while highest >= p:
        if is_prime(highest, p):
            print(highest)
            return
        highest -= 2

    print(-1)

if __name__ == '__main__':
    main()

def sieve(n):
    p = [0]*(n+1); i = 2
    while i*i <= n:
        if p[i] == 1:
            i += 1
            continue
        j = i
        while i*i + j <= n:
            p[i*i+j] = 1
            j += i
        i += 1
    k = 0
    for i in range(n+1):
        if p[i] == 0:
            k = i
    return k
p,y = map(int,input().split())
l = sieve(y)
if l > p:
    print (l)
else:
    print (-1)

from math import sqrt
p, y = [int(x) for x in input().split()]

def isprime(n):
    if n % 2 == 0 and n > 2:
        return False
    if p == 2:
        return True
    for x in range(3, min(int(sqrt(n)) + 1, p), 2):
        if n % x == 0:
            return False
    return True

for i in range(y, p,-1):
    if isprime(i):
        print(i)
        exit()
print(-1)

n,y = map(int,input().split())
l=[]
i=max(n+1,y-n-(y-n)%n)
while i<y:
	l.append(i)
	i+=1
if len(l)==0:
	print(-1)
else:
	for i in l:
		if i%n==0:
			l.remove(i)
	print(max(l))

a = input() # grasshoppers 2 to p
b = a.split() # highest branch
x = int(b[0])# grasshoppers 2 to p
y = int(b[1])# highest branch
#print (x, y)
import math
#find primes high down
search = []
for i in range(max(2, y-1000), y+1):
    search.append(i)
search = search[::-1]
#print (search)
check = 0
searcher = 0
truefail = 0
primelist = []
#print (x)
if x > 10000:
    x = 10000
fail = 0
for i in range(2, x+1):
    for j in primelist:
        fail = 0
        if (i % j) == 0:
            fail = 1
            break
    if fail == 0:
        primelist.append(i)
while check == 0:
    fail = 0
    z = min(x+1, math.floor(math.sqrt(search[searcher])+10))
    for i in range(2, z):
        #print ("CHECK", search[searcher], i)
        if (search[searcher] % i == 0):
            fail = 1
            break
    if fail == 0:
        check = 1
    else:
        searcher += 1

    if searcher > 100 or searcher == len(search):
        truefail = 1
        break
if truefail == 1:
    print (-1)
else:
    print (search[searcher])

import math
import sys

def is_prime(n, p):
    if n % 2 == 0 and n > 2:
        return False
    for i in range(3, int(math.sqrt(n)) + 1, 2):
        if i > p: break
        print(i)
        if n % i == 0:
            return False
    return True

def main():
    p, y = map(int, sys.stdin.readline().split())

    highest = y
    if y % 2 == 0:
        highest -= 1
    while highest > p:
        if is_prime(highest, p):
            print(highest)
            return
        highest -= 2

    print(-1)

if __name__ == '__main__':
    main()

p,y=map(int,input().split())

j=y
ans=-1
t=True
while j>p and t:
	for i in range(2,int(j**0.5)+1):
		if j%i==0:
			break
	else:
		t=False
		ans=j
	j-=1

print(ans)

p,y = map(int, input().split())

def is_div(a, m):
    if a % 2 == 0 or a % 3 == 0:
        return True
    i = 5
    m = min(m, a ** 0.5)
    while i < m:
        if a % i == 0 or (i + 2 < m and a % (i + 2) == 0):
            return True
        i += 6
    return False

for i in range(y - int(y % 2 == 0), p, -2):
    if not is_div(i, p):
        print(i)
        exit(0)

print(-1)

p,y = map(int,raw_input().split())
for a in xrange(y,p,-1):
	f = 1
	for b in xrange(2,min(int(a**0.5)+1,y)):
		if a%b==0:
			f = 0
			break
	if f:
		print a
		exit(0)
print -1

# -*- coding: utf-8 -*-
"""
Created on Wed Mar  7 09:39:50 2018

@author: wangjun
"""
import math

def Grasshopper(ng,nb):

    if nb%2 ==0 :
        nb=nb-1
    nng = math.floor( ng ** 0.5 )
    if nng <3:
        nng=3
    for branch in range(nb,ng,-2):
        flag =True
        for hopper in range(3,nng+1,2):
            if branch % hopper == 0:
                flag = False
                break
        if flag==True :
            return branch
    return -1

def hello():
    """Print "Hello World" and return None"""
    ar = list(map(int, input().strip().split(' ')))

    result=Grasshopper(ar[0],ar[1])
    print(result)
# main program starts here
hello()

from math import sqrt

p, y = list(map(int, input().split()))

yp = int(sqrt(y))

if yp > p:
    yp = p

if p == 2:
    if y == 2:
        print(-1)
        exit()
    if y % 2 == 0:
        print(y-1)
        exit()
    else:
        print(y)
        exit()

if yp % 2 == 0: yp += 1

if y % 2 == 0: y -= 1

if yp == 1:
    if y > 2 and y % 2 == 0:
        print(y-1)
        exit()
    else:
        print(y)
        exit()

while y > p:
    yr = yp
    while yr > 2:
        if y % yr == 0:
            yr -= 2
            break

        elif yr == 3:
            print(y)
            exit()

        elif yr > 3:
            yr -= 2

    y -= 2

print("-1")

n,m = map(int,input().split())
import math
def is_prime(n):
    if n % 2 == 0 and n > 2:
        return False
    for i in range(3, int(math.sqrt(n)) + 1, 2):
        if n % i == 0:
            return False
    return True
for x in range(m,n,-1):
    if is_prime(x):
        print(x)
        break
else:
    print (-1)

import time
p,y=map(int,input().split())
start=time.time()
def is_prime(n):

  if n == 2 or n == 3: return True
  if n < 2 or n%2 == 0: return False
  if n < 9: return True
  if n%3 == 0: return False
  r = int(n**0.5)
  f = 5
  while f <= r:
    if n%f == 0: return False
    if n%(f+2) == 0: return False
    f +=6
  return True

if(p+1>=y):
    print(-1)
else:
    ans=0
    for e in range(y,1,-1):
        if is_prime(e):
            ans=max(ans,e)
            break
    else:
        print(-1)
    if p < 10**9:
        for e in range(y,ans-1,-1):
            for i in range(2,int(y**0.5)+2):
                if(i>p):
                    continue
                if(e%i)==0:
                    break
            else:
                print(e)
                break
        else:
            print(-1)
    else:
        print(e)
"""
for e in range(y,1,-1):
    for i in range(2,p+1):
        if(e%i)==0:
            break
    else:
        print(e)
        break"""

import time
p,y=map(int,input().split())
start=time.time()
def is_prime(n):

  if n == 2 or n == 3: return True
  if n < 2 or n%2 == 0: return False
  if n < 9: return True
  if n%3 == 0: return False
  r = int(n**0.5)
  f = 5
  while f <= r:
    if n%f == 0: return False
    if n%(f+2) == 0: return False
    f +=6
  return True

if(p+1>=y):
    print(-1)
else:
    ans=0
    for e in range(y,1,-1):
        if is_prime(e):
            ans=max(ans,e)
            break
    else:
        print(-1)
    if p < 100:
        for e in range(y,ans-1,-1):
            for i in range(2,p+1):
                if(e%i)==0:
                    break
            else:
                print(e)
                break
    else:
        print(e)

for e in range(y,1,-1):
    for i in range(2,p+1):
        if(e%i)==0:
            break
    else:
        print(e)
        break

'''input
10000 100000000
'''
from math import sqrt
p=[]
pr=[1]*(10**5)
pr[1]=0
pr[0]=0

for i in range(4,10**5,2):
    pr[i]=0
for i in range(3,400,2):
    if pr[i]:
        for j in range(i*i,10**5,2*i):
            pr[j]==0
for i in range(10**5):
    if pr[i]:
        p.append(i)
def prime(n):
    sq=int(sqrt(n))+1
    for i in p:
        if i>sq:
            return True
        if n%i==0:
            return False
    return True
ppp,n=[int(x) for x in raw_input().split()]

sq=int(n**0.5)+1

lp=n
if lp%2==0:
    lp-=1
ans=-1
while lp>ppp:
    if prime(lp):
        ans=max(ans,lp)
        break
    lp-=2
pp=ppp
while sq>ppp:
    if prime(sq):
        ans=max(ans,sq*sq)
        break
    sq-=1

print ans

from math import sqrt

def modpow(a, prime, mod):
    if prime == 1:
        return a % mod
    if mod % 2 == 1:
        return (a * modpow(a, prime - 1, mod)) % mod
    return ((modpow(a, prime/2, mod)) * (modpow(a, prime/2, mod))) % mod

def isPrime(prime):
    a, b, c = 10, 27, 38
    if modpow(a, prime, prime) == (a % prime) and modpow(b, prime, prime) == (b % prime) and modpow(c, prime, prime) == (c % prime):
        return True
    return False

def minPrimeDiv(n):
    for i in range(2, int(n / 3) + 1):
        if n % i == 0 and isPrime(i):
            return i
    return 0

p, y = list(map(int, input().split()))
ans = y

done = False
s = ''
for i in reversed(range(2, y+1)):
    if minPrimeDiv(i) > p:
        s += f' {minPrimeDiv(i)}'
        print(i)
        done = True
        break
if not done:
    print(-1)

#print(s)

#print(isPrime(3), isPrime(4), isPrime(5))
#print(modpow(10, 3, 3), modpow(27, 3, 3), modpow(38, 3, 3))

from sys import stdin
def is_prime(n):
    if n <= 1:
        return False
    if n <= 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i = i + 6
    return True

x, y = map(int, stdin.readline().rstrip().split(" "))

f = 0

for i in range(x+1, y+1):
    if is_prime(i):
        f = i
        break
r = 0
if y%2==0:
    s = y-1
else:
    s = y

if f == 0:
    print(-1)

else:
    for i in range(s, y - y % f, -2):
        if is_prime(i):
            r = i
            break
    print(max(r,y -y%f))

# -*- coding: utf-8 -*-
"""
Created on Thu Mar  8 13:52:12 2018

@author: Nikita
"""

from math import ceil, sqrt
p, y = map(int, input().split())
L = [True for _ in range(y - p + 1)]
for div in range(2, max(p, ceil(sqrt(y))) + 1):
    num = div * max(div, ceil(p / div))
    while num <= y:
        L[num - p] = False
        num += div
i = len(L) - 1
L[0] = False
while i > 0:
    if L[i]:
        print(p + i)
        break
    else:
        i -= 1

if i == 0:
    print(-1)

p,y = map(int,input().split())

for x in range(y,p,-1):
	# print(x)
	# check
	flag = True
	for i in range(2,min(p,int(x**0.5)+1)):
		if x%i == 0:
			flag = False
			break
	if flag:
		print(x)
		exit()

print(-1)

n,y = map(int,input().split())
c=n*2-1
if c<y and c!=n:
	print(c)
elif c==y and c!=n:
	print(c-1)
else:
	print(-1)

import random
def FermatPrimalityTest(number):
    if (number > 1):
        for time in range(3):
            randomNumber = random.randint(2, number)-1
            if ( pow(randomNumber, number-1, number) != 1 ):
                return False

        return True
    else:
        return False

p, y = [int(x) for x in input().split()]
ans = -1
for i in range(p+1, y+1):
    if FermatPrimalityTest(i):
        ans = i
        break
print(ans)

import time
p,y=map(int,input().split())
start=time.time()
def is_prime(n):

  if n == 2 or n == 3: return True
  if n < 2 or n%2 == 0: return False
  if n < 9: return True
  if n%3 == 0: return False
  r = int(n**0.5)
  f = 5
  while f <= r:
    if n%f == 0: return False
    if n%(f+2) == 0: return False
    f +=6
  return True

if(p+1>=y):
    print(-1)
else:
    ans=0
    for e in range(y,1,-1):
        if is_prime(e):
            ans=max(ans,e)
            break
    else:
        print(-1)
    if p < 10**9:
        for e in range(y,ans-1,-1):
            for i in range(2,int(y**0.5)+2):
                if(e%i)==0:
                    break
            else:
                print(e)
                break
    else:
        print(e)
"""
for e in range(y,1,-1):
    for i in range(2,p+1):
        if(e%i)==0:
            break
    else:
        print(e)
        break"""

p,y = map(int, input().split())

def is_div(a):
    if a % 2 == 0 or a % 3 == 0:
        return True
    i = 5
    while i < a:
        if a % i == 0:
            return True
        if i + 2 < a and a % (i + 2) == 0:
            return True
        i += 6
    return False

for i in range(y, p, -1):
    if not is_div(i):
        print(i)
        exit(0)

print(-1)

import math
"""def Prime_check(x,y):
	for i in range(2,math.sqrt(y)+1):
		if(x%y==0):
			false
"""
def Prime_check(val,y):
	for i in range(2,int(math.sqrt(val))):
		if(i>y):
			break
		elif(val%i==0):
			return(False)
	return(True)
t=list(map(int,input().split()))
count=-1
if(t[0]==2 and t[0]!=t[1]):
	if(t[1]%2==0):
		print(t[1]-1)
	elif(t[1]==t[0]):
		print(-1)
	else:
		print(t[1])
elif(t[0]==t[1]):
	print(-1)
else:
	for val in range(t[1],t[0],-1):
		if(Prime_check(val,t[1])):
			print(val)
			count=1
			break
	if(count==-1):
		print(-1)

# -*- coding: utf-8 -*-
"""
Created on Wed Mar  7 09:39:50 2018

@author: wangjun
"""
import math

def Grasshopper(ng,nb):

    if nb%2 ==0 :
        nb=nb-1
    if nb == ng:
        return -1
    if ng ==2 :
        return nb
    nng = math.floor( nb ** 0.5 )
    if nng >ng :
        nng=ng

    for branch in range(nb,ng,-2):
        flag =True
        for hopper in range(3,nng+1,2):
            if branch % hopper == 0:
                flag = False
                break
        if flag==True :
            if branch > ng :
                return branch
            else:
                return -1
    return -1

def hello():
    """Print "Hello World" and return None"""
    ar = list(map(int, input().strip().split(' ')))

    result=Grasshopper(ar[0],ar[1])
    print(result)
# main program starts here
hello()

# -*- coding: utf-8 -*-
"""
Created on Wed Mar  7 09:39:50 2018

@author: wangjun
"""
import math

def Grasshopper(ng,nb):

    if nb%2 ==0 :
        nb=nb-1
    nng = math.floor( nb ** 0.5 )
    if nng >ng :
        nng=ng
    if nng < 3:
        nng=3

    for branch in range(nb,ng,-2):
        flag =True
        for hopper in range(3,nng+1,2):
            if branch % hopper == 0:
                flag = False
                break
        if flag==True :
            return branch
    return -1

def hello():
    """Print "Hello World" and return None"""
    ar = list(map(int, input().strip().split(' ')))

    result=Grasshopper(ar[0],ar[1])
    print(result)
# main program starts here
hello()

from math import ceil
def prime(x):
    if x % 2 == 0 or x % 3 == 0:
        return False

    if x == 3 or x == 5 or x == 7:
        return True

    for i in range(7, ceil(x**0.5), 2):
        if x % i == 0:
            return False

    return True

p, y = map(int, input().split())
for i in range(y, p, -1):
    if prime(i):
        print(i)
        exit()
print(-1)

from math import factorial
p, y = [int(x) for x in input().split()]
r = factorial(p)
if r - 1 > y:
    print(-1)
else:
    print(r - 1)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 25 21:50:26 2018

@author: manish
"""

d = ['3','6']

def chef(d):
    d = list(map(int,d))
    p,y = d[0], d[1]

    list1 = []
    for i in range(2,p+1):
        list1.append(i)
    m = []
    for i in range(0, len(list1)):
        for j in range(1, int(y/p)+1):
            m.append(j*list1[i])
    m.sort()

    ans = -1
    for i in range(0, len(m)-1):
        if m[i+1] != m[i]+1:
            ans = m[i]+1
            break
    return ans

def main():

    d= input().split()

    print(chef(d))

main()