object Main extends App {
	import scala.math._

	val N = scala.io.StdIn.readLine.split(" ").map(_.toLong)

	def function(a: Long, b: Long): Long = {
		val aa = min(a,b)
		val bb = max(a,b)
		
		if(aa == 1L){
			return 2L*bb -1L
		}else{
			return 2L*aa + function(aa,bb-aa)
		}
	}

	println(N(0) + function(N(1), N(0)-N(1)))

}