n, x = map((x) -> pares(x), split(readline(stdin), ' '))
longline = n-x
shortline = x

sum = x
while shortline != 0
    global sum = sum + longline + shortline
    global shortline = longline - shortline
    global longline = longline - shortline
end

println(sum)