#x, N-x, x
#N-x-x
N,x = list(map(int, input().split()))
ll = 0
if x*2 < N:
    ll = x + N
    if (N-x*2) == x:
        ll += 2*x
    elif (N-2*x) > x:
        ll += (N-x*2)/x * 2*x
    else :
        ll += x + x/(N-x*2)*2-(N-x*2)
elif x*2 == N:
    ll = x + x + x
else:
    ll = x
    ll += x/(N-x)*2
print(int(ll))
