n=gets.to_i+1 a=(0..n).map{|i|i.to_s(2).count ?1};a[0]=1 r=[0] n.times{|i| n.times{|j| next if r[j]!=i x,y=j-a[j],j+a[j] r[x]=i+1 if !r[x]&&x>0 r[y]=i+1 if !r[y]&&y