def milor(a,b):
    if a == b:
        return a
    if a > b:
        a,b = b,a
    return milor(b-a,a) + 2*a

def solve(n,x):
    res = n + milor(x,n-x)
    return res



if __name__ == '__main__':
    n,x = map(int,input().split())
    print(solve(n,x))