object Main extends App {
	
	def fun(a: Long, b: Long): Long = {
		if(a> b){
			return fun(b, a)
		}
		if(a == b){
			return a
		}else{
			if(b%a == 0){
				return 2*a + fun(a, b-a)
			}else{
				return 2* math.floor(b/a).toLong * a + fun(a, b%a)
			}
		}
	}

	var Array(n, x) = scala.io.StdIn.readLine.split(" ").map(_.toLong)
	val y = n - x

	println(fun(x,y) + n)
	

}