program test 
implicit none

character(len=100)  s
integer(8) :: i,j,k,l,m,n,a,b,ans,ans2
integer ::ss

ans = 0

read(*,*) s
read(*,*) k

n = len_trim(s)

do i=1,n
read (s(i:i),*) ss

if( ss == 1 ) then
ans = ans + 1
if(ans == k) then
write(*,*) ss
goto 10
endif
else
write(*,*) ss
goto 10
endif

enddo

10 continue

end program