L = map(int, raw_input().split())
n = L[0]
x = L[1]
res = n
a = x
b = n-x
flag = True
while flag :
    if a > b:
        a -= b
        res += 2*b
    elif  b > a:
        b -= a
        res += 2*a
    else:
        res += a
        flag = False
print(res)