ICPC University sets its doctoral graduation requirement from the number of papers a student has published and how often those papers are cited, and it measures this with a value called the q-index. Suppose a student has published n papers, where n≥1. The student's q-index is k when at least k papers are cited k or more times and each of the remaining n−k papers is cited at most k times.
Take a student with 5 papers cited 8, 4, 5, 3, and 10 times. At least one paper is cited one or more times, but some of the other 4 papers are cited more than once, so the q-index is not 1. Fewer than 5 papers are cited 5 or more times, so it is not 5 either. Exactly 4 papers are cited 4 or more times and the one remaining paper is cited at most 4 times, so this student's q-index is 4.
Write a program that reads the citation counts of one student's papers and computes that student's q-index.