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
     
    !write(*,*)"sort",sort
    !write(*,*)"a   ",a
    !write(*,*)
  end do

  do i=1,n
     if(sum(sort(1:i)).gt.have)then
        !ans=sum(a(1:i-1))
        exit
     end if
  end do
  if(sum(sort(1:i-1)).ne.have) i=i-1
  
  !write(*,*)"sort",sort
  write(*,*)i-1!,ans

end program main
