n, x = map((x) -> parse(Int, x), split(readline(stdin), ' '))
function a()
    longline = n-x
    shortline = x

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

    println(sum)
end
a()