package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)

func readNum() int {
	var str, _ = reader.ReadString('\n')
	var trimmed = strings.TrimSpace(str)
	var i, _ = strconv.Atoi(trimmed)
	return i
}

func leadSplit() []string {
	var str, _ = reader.ReadString('\n')
	var trimmed = strings.TrimSpace(str)
	var values = strings.Split(trimmed, " ")
	return values
}

func toNum(str string) int {
	var s, _ = strconv.Atoi(str)
	return s
}

func toInts(strs []string) []int {
	var results = make([]int, 0)
	for _, v := range strs {
		results = append(results, toNum(v))
	}
	return results
}

func main() {
	var nunms = toInts(leadSplit())
	var n = nunms[0]
	var x = nunms[1]
	fmt.Println(n + lightLen(x, n-x))
}
func lightLen(a, b int) int {
	if a < b {
		return 2*b + lightLen(b-a, a)
	} else if b < a {
		return 2*a + lightLen(a, a -b)
	} else {
		return a
	}

}
