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

def para(a,b)
  short,long = [a,b].sort
  if short == long
    return short
  elsif short < long
    return short * 2 + para(long-short,short)
  end
end

short,long = [x,n-x].sort

puts n + para(short,long)
