Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly $1$ problem, during the second day — exactly $2$ problems, during the third day — exactly $3$ problems, and so on. During the $k$-th day he should solve $k$ problems.

Polycarp has a list of $n$ contests, the $i$-th contest consists of $a_i$ problems. During each day Polycarp has to choose exactly one of the contests he didn't solve yet and solve it. He solves exactly $k$ problems from this contest. Other problems are discarded from it. If there are no contests consisting of at least $k$ problems that Polycarp didn't solve yet during the $k$-th day, then Polycarp stops his training.

How many days Polycarp can train if he chooses the contests optimally?


-----Input-----

The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of contests.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2 \cdot 10^5$) — the number of problems in the $i$-th contest.


-----Output-----

Print one integer — the maximum number of days Polycarp can train if he chooses the contests optimally.


-----Examples-----
Input
4
3 1 4 1

Output
3

Input
3
1 1 1

Output
1

Input
5
1 1 1 2 2

Output
2

Difficulty: introductory

Starter code:

Solutions:
def main():
    n = int(input())
    arr = sorted(map(int, input().split()))
    j = 1
    for x in arr:
        if x >= j:
            j += 1
    print(j - 1)
    return 0

main()

n = int(input())
l = sorted(map(int, input().split()))
i = 0
res = 0
while i < n:
    if res < l[i]:
        res += 1
    i += 1
print(res)

# AC
import sys


class Main:
    def __init__(self):
        self.buff = None
        self.index = 0

    def __next__(self):
        if self.buff is None or self.index == len(self.buff):
            self.buff = self.next_line()
            self.index = 0
        val = self.buff[self.index]
        self.index += 1
        return val

    def next_line(self):
        return sys.stdin.readline().split()

    def next_ints(self):
        return [int(x) for x in sys.stdin.readline().split()]

    def next_int(self):
        return int(next(self))

    def solve(self):
        n = self.next_int()
        x = sorted(self.next_ints())
        res = 0
        for _x in x:
            if _x > res:
                res += 1
        print(res)


def __starting_point():
    Main().solve()

__starting_point()

n = int(input())
A = list(map(int, input().split()))
A.sort()
k = 1
for i in A:
    if i >= k:
        k += 1
print(k - 1)

n = int(input())
a = sorted(list(map(int, input().split())))
count = 0
h = 1
for i in range(n):
    if a[i] >= h:
        h += 1
        count += 1
print(count)

n = int(input())
a = list(map(int, input().split()))
sa = sorted(a)
ptr = 0
for i in range(1, n + 2):
    while ptr < n and sa[ptr] < i:
        ptr += 1
    if ptr == n:
        print(i - 1)
        break
    ptr += 1


n = int(input())
u = list(map(int, input().split()))
u.sort()
ans = 0
for i in range(n):
    if ans < u[i]:
        #5print(ans, u[i])
        ans += 1
print(ans)


def main():
    from sys import stdin, stdout

    def read():
        return stdin.readline().rstrip('\n')

    def read_array(sep=None, maxsplit=-1):
        return read().split(sep, maxsplit)

    def read_int():
        return int(read())

    def read_int_array(sep=None, maxsplit=-1):
        return [int(a) for a in read_array(sep, maxsplit)]

    def write(*args, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in args) + end)

    def write_array(array, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in array) + end)

    n = read_int()
    a = read_int_array()
    a.sort()
    out = 0
    for x in a:
        if x >= out + 1:
            out += 1
    write(out)

main()


n = int(input())
s = sorted([int(i) for i in input().split()])
need = 1
for i in s:
	if i >= need:
		need += 1
print (need - 1)

IN = input
rint = lambda: int(IN())
rmint = lambda: list(map(int, IN().split()))
rlist = lambda: list(rmint())

n = rint()
a = rlist()
a.sort()
k = 1
for c in a:
    if c >= k: k += 1
print(k-1)


n = int(input())
a = list(map(int, input().split()))
a.sort()
contest = 1
for i in range(n):
    if a[i] >= contest:
        contest += 1
print(contest-1)


n=int(input())
A=list(map(int,input().split()))
A.sort()
ANS=1

for a in A:
    if a>=ANS:
        ANS+=1

print(ANS-1)


n=int(input())
a=[int(s) for s in input().split()]
a.sort()
cur=1
ans=0
for i in range(n):
    if a[i]>=cur:
        cur+=1
        ans+=1
print(ans)

n=int(input())
l=list(map(int,input().split()))
l.sort()
count=0
for i in l:
	if i>count:
		count+=1
print (count)

n = int(input())
t = list(map(int,input().split()))
t.sort()
count=0
for i in range(n):
	if(t[i]>=count+1):
		count+=1
print(count)

n=int(input())
a=sorted(list(map(int,input().split())))
ans=0
k=1
for i in a:
    if i>=k:
        ans+=1
        k+=1
print(ans)

n=int(input())
l1=list(map(int,input().split()))
l1.sort()
i=0
ans=0
while i<len(l1):
    if l1[i]>=ans+1:
        i+=1
        ans+=1
    else :
        i+=1
print(ans)

n = int(input())
lst = list(map(int, input().split()))
lst.sort()
dayCount = 0
for i in lst:
    if i >= dayCount+1:
        dayCount += 1
print(dayCount)

n = int(input())
l = list(map(int, input().split()))
l.sort(    )
k = 1
for i in l:
    if i >= k:
        k += 1
print(k - 1)

#n = int(input())
#n, m = map(int, input().split())
#d = list(map(int, input().split()))

n = int(input())
d = sorted(map(int, input().split()))

r = 0
j = 1
for i in range(n):
    if j <= d[i]:
        r+=1
        j+=1
print(r)




n = int(input())
sp = list(map(int, input().split()))
sp.sort()
k = 1
ind = 0
while ind != n:
	if sp[ind] >= k:
		k += 1
	ind += 1
print(k - 1)


import math
import bisect
import heapq
from collections import defaultdict


def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, x, y = egcd(b % a, a)
        return (g, y - (b // a) * x, x)


def mulinv(b, n):
    g, x, _ = egcd(b, n)
    if g == 1:
        return x % n



def isprime(n):
    for d in range(2, int(math.sqrt(n))+1):
        if n % d == 0:
            return False
    return True


def argsort(ls):
    return sorted(range(len(ls)), key=ls.__getitem__)


def f(p=0):
    if p == 1:
        return map(int, input().split())
    elif p == 2:
        return list(map(int, input().split()))
    elif p == 3:
        return list(input())
    else:
        return int(input())


n = f()
cl = sorted(f(2))
count = cl[-1]
res = n
for i in range(n-2, -1, -1):
    count = min(cl[i], count-1)
    if count==0:
        res = n-i-1
        break


print(res)

n=int(input())
a=[int(x) for x in input().split()]
a.sort()
counter=0
i=1
uk=0
while uk<n:
    if a[uk]<i:
        uk+=1
    else:
        counter+=1
        uk+=1
        i+=1
print(counter)
    


n = int(input())
mas = [int(i) for i in input().split()]
mas = sorted(mas)
k = 1
for i in range(n):
    if mas[i] >= k:
        k += 1
print(k-1)