use v5.16; my $L = <>; my $N = <>; my $W = <>; chomp( $L, $N, $W ); my @W = sort { $a <=> $b } ( split / /, $W ); while ( my ( $i, $e ) = each @W ) { $L = $L - $e; if ( $L < 0 ) { say $i; exit; } } say( scalar @W ) + 1;