At least h with at least h Input

A list of nonnegative integers.

Output

The largest nonnegative integer h such that at least h of the numbers in the list are greater than or equal to h.

Test Cases

[0,0,0,0] -&gt; 0
[12,312,33,12] -&gt; 4
[1,2,3,4,5,6,7] -&gt; 4
[22,33,1,2,4] -&gt; 3
[1000,2,2,2] -&gt; 2
[23,42,12,92,39,46,23,56,31,12,43,23,54,23,56,73,35,73,42,12,10,15,35,23,12,42] -&gt; 20


Rules

You can write either a full program or a function, and anonymous functions are allowed too. This is code-golf, so the fewest byte count wins. Standard loopholes are disallowed.

Background

The h-index is a notion used in academia which aims to capture the impact and productivity of a researcher. According to Wikipedia, a researcher has index h, if he or she has published h scientific articles, each of which has been cited in other articles at least h times. Thus, this challenge is about computing the h-index from a list of citation counts.



Update

Wow, great answers all round! I have accepted the shortest one, but if someone else comes up with an even shorter one, I'll update my choice accordingly.

Winners by language

Here's a table of winners by language that I'll also try to keep up to date. I have included all posts with nonnegative score. Please correct me if I have made a mistake here.


APL: 7 bytes by @MorisZucca
Bash + coreutils: 29 bytes by @DigitalTrauma
C#: 103 bytes by @LegionMammal978
C++: 219 bytes by @user9587
CJam: 15 bytes by @nutki
GolfScript: 13 bytes by @IlmariKaronen
Haskell: 40 bytes by @proudhaskeller
J: 12 bytes by @ɐɔıʇǝɥʇuʎs
Java: 107 bytes by @Ypnypn
JavaScript: 48 bytes by @edc65
Mathematica: 38 bytes by @kukac67
Perl: 32 bytes by @nutki
Pyth: 10 bytes by @isaacg
Python: 49 bytes by @feersum
R: 29 bytes by @MickyT
Ruby: 41 bytes by @daniero
Scala: 62 bytes by @ChadRetz
SQL: 83 bytes by @MickyT
TI-BASIC: 22 bytes by @Timtech
Python, 52

f=lambda s,n=0:n&lt;sum(n&lt;x for x in s)and f(s,n+1)or n


A recursive solution. Run this in Stackless Python if you're worried about overflows.

Starting from n=0, checks whether at least n+1 of the numbers are at least n+1. If so, increments n and starts again. If not, outputs n.

The conditional is done using Python's short-circuiting for Booleans. The expression sum(n&lt;x for x in s) counts the number of values in s that are greater than n by adding the indicator Booleans, which are treated as 0 or 1.

For comparison, the iterative equivalent is 2 chars longer. It requires Python 2.

s=input()
n=0
while n&lt;sum(n&lt;x for x in s):n+=1
print n


Unfortunately, the input need to be saved for a variable before being iterated over or else Python will try to read the input repeatedly.