N, X = map(int, input().split(" "))

e_long = max(X, N-X)
e_short = N - e_long

total = N

while e_long != e_short and e_long > 0 and e_short > 0:
    total += e_short * 2
    e_long -= e_short
    if e_short > e_long:
        tmp = e_long
        e_long = e_short
        e_short = tmp

total += e_short

print(total)