This page is still under construction.

Parts of this page are still being built. What you see may change.

Q-index

Interview

Time limit1sMemory limit512 MB

Summary
Given n citation counts, find the largest k such that at least k papers have k or more citations and the rest have at most k.
Level

Medium4 of 10

Topics
Sorting, Array
Solved
No attempts yet

Problem

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 nn papers, where n≥1n \ge 1. The student's q-index is kk when at least kk papers are cited kk or more times and each of the remaining n−kn - k papers is cited at most kk 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.

Input

The first line contains the number of papers nn the student published, where 1≤n≤10001 \le n \le 1000. The second line contains the citation counts of the nn papers in order, separated by spaces. Each citation count is an integer between 0 and 10000.

Output

Print the q-index on one line. The value is a non-negative integer.

Examples3

  1. Example 1

    Input
    5
    8 4 5 3 10
    
    Expected output
    4
    
  2. Example 2

    Input
    4
    0 0 0 0
    
    Expected output
    0
    
  3. Example 3

    Input
    6
    12 7 6 8 9 10
    
    Expected output
    6