Peter is a picky eater! There is a boy named Peter. Peter is a picky eater and doesn't like to eat the same kind of cookie again on the same day.
Peter gets a present, The present is a box of cookies! The box contains \$K\$ types of cookies. Also, it contains different amount of each type of cookie.
Peter, being the picky eater he is, Wants to eat \$n\$ cookies, on each \$n^{th}\$ day. Also, he does not want to eat more than 1 cookie of the same kind on any given day.
i.e. He eats \$1\$ cookie on the \$1^{st}\$ day, \$2\$ cookies on the \$2^{nd}\$ day and so on.
If there is no possible way for Peter to eat \$n\$ cookies at day \$n\$, he gives up and dumps the box. He also dumps the box if it becomes empty.
Find the maximum number of days that the box will last for Peter.
Input
\$K\$ Positive Integers, specifying the number of cookies for each different kind.
Output
An Integer corresponding to how many days Peter keeps the box.
Test Cases
INPUT -&gt; OUTPUT
1 2 -&gt; 2
1 2 3 -&gt; 3
1 2 3 4 4 -&gt; 4
1 2 3 3 -&gt; 3
2 2 2 -&gt; 3
1 1 1 1 -&gt; 2
11 22 33 44 55 66 77 88 99 -&gt; 9
10 20 30 40 50 60 70 80 -&gt; 8
3 3 3 3 3 3 3 3 3 3 3 -&gt; 7
3 3 3 3 3 3 3 3 3 -&gt; 6
9 5 6 8 7 -&gt; 5
1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 -&gt; 35
1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 -&gt; 32

Gist for test cases
This is code-golf so the shortest code wins.
Perl 5, 79 77 76 75 69 (rip) 68 64 62 bytes
Credit to @Lynn for improving my answer by 4 bytes (68 to 64) and the explanation about the comma operator in scalar context here https://docstore.mik.ua/orelly/perl2/prog/ch03_18.htm
Thanks @Nahuel Fouilleul for the tip using anonymous functions to save 2 bytes (64 to 62) but if it's not allowed I'll revert back
sub{$^=0;++$^while(@_=sort{$b-$a}@_),!grep--$_[$_]&lt;0,0..$^;$^}

Test Cases Here: Try it online!
Expanded:
sub {                       # Declare subroutine
    $^ = 0;                 # Set scalar caret variable to 0 (you can put this variable right next to if statements and for loops etc)
    ++$^ while              # Pre increment caret while the condition below is true
        (                   # Bracket used so that you can declare/reassign values in a conditional
            @_ = sort {     # Sort the default array and store result back to default array
                $b - $a     # Sort from greatest to least (scalar variables a and b are default variables that come with sort)
            }@_             # Add the default array as a parameter for the sort
        ),                  # End of bracket (in scalar context like in this solution it will only grab the right most argument of the array so the while loop is entirely dependent on the condition below)
        !grep               # Only save values if the below statement is true for each item in default array then reverse the boolean (will return false if the size of the array after grep is greater than 0)
            --$_[$_] &lt; 0,   # Check whether the pre decrement of item (default is $_) at the index of default array is less than 0. If the caret is out of range of the array, it will default to undef which is treated as 0 in math operations)
        0 .. $^             # Add an array of range 0 to caret inclusive to the grep
    ;                       # End of the while loop statement modifier
    $^                      # Return caret variable
}                           # End of subroutine