package main

import "fmt"

func solve(n, x int) {
	if n%2 == 0 && n/2 == x {
		fmt.Println(x * 3)
	} else {
		fmt.Println(x*3 + (n - x) + (n-x-x)*3)
	}
}

func main() {
	var n, x int
	fmt.Scan(&n)
	fmt.Scan(&x)
	solve(n, x)
}
