spoj#BOPERISH. E - Publish of Perish

E - Publish of Perish

PROBLEM E

 PUBLISH OF PERISH

“Publish or perish” is the academic life’s fundamental motto. It refers to the fact that publishing your work frequently is the only way to guarantee access to research funds, bright students and career advances. But publishing is not enough. It is necessary that your work is referenced (or cited). That is, your papers must be mentioned as source of information in other people’s publications, to attest the quality and relevance of your research. The more citations a paper receives from other authors, the more it is considered influential.

In 2005 Jorge E. Hirsch, a physicist at the University of California at San Diego, proposed a way to evaluate the scientific impact of a researcher, based on the citations his or her papers have received. The h-index, as Hirsch’s proposal became known, is a number based on the set of a researcher’s most cited papers. It is defined in Hirsch’s own words as: A scientist has index h if h of his Np papers have at least h citations each, and the other (Np − h) papers have at most h citations each.

Albert Einstein, for example, published 319 papers in scientific journals and has an h-index equal to 46. It means 46 of his papers have received 46 or more citations each, and all of his remaining 273 papers have 46 citations or less each. Given the information of how many citations each paper from a given researcher has received, write a program to calculate that researcher’s h-index.

Input

The input contains several test cases. The first line of a test case contains one integer N indicating the number of papers a researcher has published (1<=N<=103). The second line contains a list of N integers Mi, separated by one space, representing the number of citations each of the N papers from that author has received (0<=Mi <=103, for 1<= i <= N). The end of input is indicated by a line containing only one zero.

Output

For each test case in the input, your program must print a single line, containing one single integer, the h-index for the given list of citations.

Sample Input

4

1003 1 200 2

10

1 1 1 0 1 1 0 1 1 1

7

6 5 4 3 2 1 0

0

Sample Output

2

1

3