PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000086. Dãy đặc biệt với đúng x phần tử đủ lớn (Special Array With X Elements Greater Than or Equal X)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Dãy đặc biệt với đúng x phần tử đủ lớn (Special Array With X Elements Greater Than or Equal X)

Special Array With X Elements Greater Than or Equal X

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn nonnegative integers, find a nonnegative integer xx for which exactly xx elements are at least xx. The value need not appear in the array. Output −1-1 if none exists; a valid xx is unique.

Input

The first line contains nn; the second line contains the nn values.

Output

Print xx if the array is special, otherwise -1.

Subtasks

  • Subtask 1 (20 points): 1≤n≤121\le n\le12; 0≤ai≤10000\le a_i\le1000.
  • Subtask 2 (30 points): 1≤n≤501\le n\le50; 0≤ai≤10000\le a_i\le1000.
  • Subtask 3 (50 points): 1≤n≤1001\le n\le100; 0≤ai≤10000\le a_i\le1000.

Examples

Input

5
0 4 3 0 4

Output

3

Explanation

For x=3x=3, exactly three values (4,3,44,3,4) are at least 33. Thus x=3x=3 meets the condition and is the unique answer.