N, X=map(int, input().split())

A = sorted([X, N - X, N, N - X], reverse=True)

while True:
        if A[0] == A[1]:
                A[0] -= A[2]
        else:
                A[0] -= A[1]
        if A[0] == 0:
                break
        A.sort(reverse = True)

print(3*N - sum(A))
