Python 2, 81 bytes
1-based indexing
l=[0];p=0
exec"n=0\nwhile(p^n)&(p^n)-1or n in l:n+=1\np=n;l+=p,;"*input()
print p
Python 2, 79 bytes
This takes a lot of time (9999 wasn't finished after running locally for 7 minutes)
l={0};p=0;n=input()
exec'p=min({p^2**k for k in range(n)}-l);l|={p};'*n
print p