def drunken_knight(L, i0):
    i = i0
    while 0 <= i < len(L) and L[i] != -1:
        L[i], i = -1, L[i]
