num = [int(x) for x in input().split()]
N = num[0]
X = num[1]
result = N
a = N -X
b = X
if a < b:
    c = a
    a = b
    b = c
while b >= 1:
    result += (2*(a//b))*b
    c = a%b
    a = b
    b = c
print(result)