program answer
  implicit none
  integer(16) :: N, i, j, count, YY, eg, e
  integer(16), allocatable :: X(:), f(:), Y(:)
  read(*,*) N
  allocate(Y(N))
  read(*,*) eg
  allocate(X(N))
  allocate(f(N))

  do i = 1, N
     if(eg/(10**(N-i))==1) then
        Y(i)=1
        eg=eg-10**(N-i)
     else
        Y(i)=0
     end if
  end do

  YY=0
  do i = 1, N
     YY=YY+(2**(N-i))*Y(i)
  end do

  do i = 1, N
     if(Y(i)==1) then
        X(i)=YY-2**(N-i)
     else
        X(i)=YY+2**(N-i)
     end if
  end do

  do i = 1, N
     count=0
     e=X(i)
     do
        if(pop(e)==0) then
           exit
        end if
        e=pop(e)
        count=count+1
     end do
     write(*,*) count
  end do

  deallocate(Y)
  deallocate(X)
  deallocate(f)
  stop
contains
  integer(16) function pop(s)
    implicit  none
    integer(16) :: s, i, count
    count=0
    do
       if(s==0) then
          exit
       end if
       if(mod(s,2)==1) then
          count=count+1
       end if
       s=s/2
    end do

    end if
    pop=count
    return
  end function pop
 end program answer

       

    
     
     
  
  
