package main

import (
	"fmt"
)

func main() {
	var n, x int
	fmt.Scan(&n, &x)
	if 2*x > n {
		x = n - x
	}
	if n%2 == 1 {
		fmt.Println((n - 1) * 3)
	} else {
		a := (n - 1) * 3
		b := (x - 1) * 3
		fmt.Println(a - b)
	}
}
