n,x = gets.split.map(&:to_i)

def para(short,long)
  if short == long
    return short
  elsif short < long
    return short * 2 + para(long-short,short)
  end
end

if x > n-x
  a = n-x
  b = x
else
  a = x
  b = n-x
end

puts n + para(a,b)
