divisor = int(input())
bound = int(input())

for n in range(bound + 1, 0 , -1):
    if (n % divisor == 0) and (n <= bound) and (n > 0):
        print(n)
        break

61bf90382a050d807bd4a9910399e6663a64a94a
<mask token>

<mask token>
for n in range(bound + 1, 0, -1):
    if n % divisor == 0 and n <= bound and n > 0:
        print(n)
        break

divisor = int(input())
bound = int(input())
for n in range(bound + 1, 0, -1):
    if n % divisor == 0 and n <= bound and n > 0:
        print(n)
        break

divisor = int(input())
bound = int(input())

for n in range(bound + 1, 0 , -1):
    if (n % divisor == 0) and (n <= bound) and (n > 0):
        print(n)
        break
