    mLen = len(bin(M)) - 2
    for x in range(mLen):
        if M & (1 << x):
            t3 += 1
            t1, t2 = t2, t1
        else:
            t1 += 1
            t2, t3 = t3, t2
    left = N - mLen