def func a, b
    if a==b
        return a
    else
        min = [a, b].min
        return 2*min + func((a>min) ? a-min : a, (b>min) ? b-min : b)
    end
end

n, x  = gets.chomp.split.map(&:to_i)
puts n + func(x, n - x)
