import java.util.*;

public class Stones {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int ans =0;
        int s= (int)Math.min(k-1,n-k);
        int sec = 4;
        int last = 2;

        for(int i=2; i<n; i++)
        {
            ans=ans+3;
        }
        System.out.println(ans+s+sec+last);
    }
}
