n, x = map(int, input().split())


if (n%2 == 1):
    print((n-1)*3)
elif (n==2):
    print(3)
else:
    k=n/2
    if (x<k):
        if((n/2)%2==0):
            l = []
            for i in range(1,k-2):
                l.append(((n-1)*3)-3*(x-1))
            last = l[0]
            l.append(last)
            print(l[x-1])
        else:
            if (x%2==0):
                print((n-2)*3)
            else:
                print((n-1)*3)
    elif(x==k):
        print(int(k*3))
    else:
        p = n-x
        if (p<k):
            if((n/2)%2==0):
                l = []
                for i in range(1,k-2):
                    l.append(((n-1)*3)-3*(p-1))
                last = l[0]
                l.append(last)
                print(l[p-1])
            else:
                if (p%2==0):
                    print((n-2)*3)
                else:
                    print((n-1)*3)
