F,P = map(int,input().split()) #7 3
def f(Q, deep):
if deep == 5:
return Q
for x in range(Q, 100*Q):
if x == Q+ (F-P)*(x//F):
break
return f(x,deep+1)
print(f(F,1))
# 12 тест не проходит
import matplotlib.pyplot as plt
import random
random.seed(42)
v = []
x = list(range(20))
y = [random.randint(1,85) for i in range(20)]
for i in range(1,len(y)):
v.append(y[i]-y[i-1])
v.append(v[-1])
plt.plot(x,y)
plt.plot(x,v,color="C1")
plt.show()