program main
  implicit integer(a-z)
  allocatable::a(:)
  allocatable::sort(:)

  read(*,*)n,have
  allocate(a(n))
  allocate(sort(n))
  read(*,*)(a(i),i=1,n)

  do i=1,n
     sort(i)=minval(a(1:n-i+1))
     tmp=minval(a(1:n-i+1))
     do j=1,n-i+1
        if(tmp.eq.a(j)) exit
     end do
     a(j)=a(n-i+1)
     a(n-i+1)=tmp
  end do

  do i=1,n
     if(sum(sort(1:i)).gt.have)then
        exit
     end if
  end do

  if(i-1.eq.n .and. sum(sort).ne.have) i=i-1
  
  write(*,*)i-1

end program main
