use warnings; my $l = <>; my $n =<>; my $str = <>; chomp $str; my @array = split / /, $str; my $ans = 0; my $count = 0; @array = sort {$a <=> $b} @array; for(my $i = 0; $i < $n; $i++) { $count += $array[$i]; if($count < $l) { $ans++; } else { last; } } print "$ans\n";