Training Site
Sideways banner

Carpentry

Input: Standard Input (stdin)
Output: Standard Output (stdout)
Memory limit: 64 megabytes
Time limit: 1.0 seconds

Living out in the wilderness is great, but the ol' log cabin is in dire need of an upgrade, so you've decided to append a second floor to the structure. Naturally, to reach the second floor, you're going to need to build a set of stairs. You've compiled a list of N logs that are optimal for stair making, each of which have some height. A set of stairs consists of a sequence of logs, where the first one is of height 1, the second is of height 2, and so on up to the top. Using your axe you can reduce the height of any log by any amount, discarding any offcuts. Given the heights of each of your N logs, you would like to know the highest set of stairs you could possibly make.

Input

The first line of input contains as integer N.

The second line contains N space-separated integers h_0 h_1 ... h_{n-1}, where h_i is the height of the ith log.

Output

Output a single integer: The maximum height stairs you can build using the logs you have.

Constraints

  • 1 ≤ N ≤ 100,000

  • 1 ≤ h_i ≤ 10^9

Subtasks

  • Subtask 1 (10%): N = 3
  • Subtask 2 (10%): h_i ≤ 5
  • Subtask 3 (20%): N ≤ 1,000
  • Subtask 4 (60%): No additional constraints apply.

Sample Explanations

Sample Input 1

Here you have three logs, each of height 2. You can use your axe to reduce the height of the first log to 1. Then, you can use that log and another log of height 2 to form a staircase of height 2.

Sample Input 2

If you shrink the size of the third log down to 3, you would have logs of height [1,2,3] so can form a staircase of height 3.

  • Sample Input 1

    3
    2 2 2
    

    Sample Output 1

    2
    
  • Sample Input 2

    3
    1 2 4
    

    Sample Output 2

    3