You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N).
Your objective is to remove some of the elements in a so that a will be a good sequence.
Here, an sequence b is a good sequence when the following condition holds true:
 - For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be a good sequence.

-----Constraints-----
 - 1 \leq N \leq 10^5
 - a_i is an integer.
 - 1 \leq a_i \leq 10^9

-----Input-----
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N

-----Output-----
Print the minimum number of elements that needs to be removed so that a will be a good sequence.

-----Sample Input-----
4
3 3 3 3

-----Sample Output-----
1

We can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good sequence.

Difficulty: EASY

Starter code:

Solutions:
import collections
N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
C = collections.Counter(L)
D = list(C.keys())
E = list(C.values())
K = len(C)
ans = 0
for i in range(K):
	if D[i] == E[i]:
		ans += 0
	if D[i] > E[i]:
		ans += E[i]
	if D[i] < E[i]:
		ans += E[i] - D[i]
print(ans)


n = int(input())
a = list(map(int, input().split()))
ans = 0
from collections import defaultdict
dd = defaultdict(int)
for key in a:
	dd[key] += 1
for key in dd.keys():
	if dd[key] >= key:
		ans += dd[key] - key
	else:
		ans += dd[key]
print(ans)


n = int(input())
a = list(map(int, input().split()))
dict = {}
for i in range(n):
	if a[i] not in dict:
		dict[a[i]] = 1
	else:
		dict[a[i]] += 1
ans = 0
for i in dict:
	if dict[i] < i:
		ans += dict[i]
	elif dict[i] == i:
		continue
	else:
		ans += dict[i] - i
print(ans)


def main():
	n = int(input())
	inlis = list(map(int, input().split()))
	adic = dict()
	ans = 0
	for i in range(n):
		a = inlis[i]
		if a not in adic:
			adic[a] = 1
		else:
			adic[a] += 1
		if adic[a] > a:
			ans += 1
	for num in adic:
		if adic[num] < num:
			ans += adic[num]
	print(ans)

def __starting_point():
	main()
__starting_point()


n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
	if i not in d:
		d[i] = 1
	else:
		d[i] += 1
print(sum([j if i > j else j - i for (i, j) in d.items()]))


from collections import Counter
N = int(input())
A = Counter(list(map(int, input().split())))
res = 0
for (values, counts) in list(A.items()):
	if values > counts:
		res += counts
	elif values < counts:
		res += counts - values
print(res)


N = int(input())
(*A,) = map(int, input().split())
import collections
c = collections.Counter(A)
ans = 0
for (k, v) in c.items():
	if k == v:
		continue
	if k < v:
		ans += v - k
	if v < k:
		ans += v
print(ans)


import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def S_MAP():
	return map(str, input().split())

def LIST():
	return list(map(int, input().split()))

def S_LIST():
	return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()
S = set(A)
C = Counter(A)
cnt = 0
for s in S:
	if C[s] != s:
		if C[s] > s:
			cnt += C[s] - s
		else:
			cnt += C[s]
print(cnt)


from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
hashmap = defaultdict(int)
for a in A:
	hashmap[a] += 1
ans = 0
for (k, v) in hashmap.items():
	if k < v:
		ans += v - k
	elif k > v:
		ans += v
print(ans)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
count = 0
for (i, j) in Counter(a).items():
	if j - i < 0:
		count += j
	else:
		count += min(j - i, j)
print(count)


n = int(input())
a = [int(i) for i in input().split()]
dp = [0] * (n + 2)
for i in a:
	if i > n:
		dp[-1] += 1
	else:
		dp[i] += 1
ans = dp[-1]
for i in range(1, n + 1):
	if dp[i] >= i:
		ans += dp[i] - i
	else:
		ans += dp[i]
print(ans)


import collections
N = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
ans = 0
for (i, j) in c.items():
	if i > j:
		ans += j
	elif j > i:
		ans += j - i
print(ans)


import sys
from collections import Counter
sys.setrecursionlimit(10 ** 8)
ini = lambda : int(sys.stdin.readline())
inl = lambda : [int(x) for x in sys.stdin.readline().split()]
ins = lambda : sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print('\x1b[33m', *a, '\x1b[0m', **dict(file=sys.stderr, **kw))

def solve():
	n = ini()
	a = inl()
	c = Counter()
	for x in a:
		c[x] += 1
	ans = 0
	for (k, v) in c.items():
		if k <= v:
			ans += v - k
		else:
			ans += v
	return ans
print(solve())


from collections import Counter

def mapt(fn, *args):
	return tuple(map(fn, *args))

def Input():
	return mapt(int, input().split(' '))

def main():
	n = int(input())
	a = Counter(Input())
	ans = 0
	for (key, val) in a.items():
		x = val - key
		if x < 0:
			ans += val
		elif x > 0:
			ans += x
	print(ans)
main()


from collections import Counter
N = input()
list1 = list(map(int, input().split()))
dict1 = Counter(list1)
key1 = list(dict1.keys())
value1 = list(dict1.values())
ans = 0
for i in range(len(key1)):
	x = value1[i]
	y = key1[i]
	if x >= y:
		ans += x - y
	else:
		ans += x
print(ans)


from collections import Counter
input()
a = Counter(map(int, input().split()))
print(sum((j if i > j else j - i for (i, j) in a.items())))


import sys
from collections import Counter
input = lambda : sys.stdin.readline().rstrip()

def main():
	n = int(input())
	a = Counter(list(map(int, input().split())))
	ans = 0
	for (k, v) in a.items():
		if k < v:
			ans += v - k
		elif k > v:
			ans += v
	print(ans)

def __starting_point():
	main()
__starting_point()


N = int(input())
a = list(map(int, input().strip().split()))
d = {}
for n in range(N):
	if d.get(a[n]) == None:
		d[a[n]] = 1
	else:
		d[a[n]] += 1
cnt = 0
for key in list(d.keys()):
	if key > d[key]:
		cnt += d[key]
	else:
		cnt += d[key] - key
print(cnt)


from collections import Counter
N = int(input())
A = list(map(int, input().split()))
A = Counter(A)
cnt = 0
for (i, j) in list(A.items()):
	if i > j:
		cnt += j
	elif i < j:
		cnt += j - i
print(cnt)


n = int(input())
a = list(map(int, input().split()))
d = {}
cnt = 0
for i in range(n):
	if a[i] not in d:
		d[a[i]] = 1
	else:
		d[a[i]] += 1
for key in list(d.keys()):
	if d[key] != key:
		if d[key] < key:
			cnt += d[key]
		else:
			cnt += d[key] - key
print(cnt)


import os
import sys
from collections import Counter

def main():
	N = int(input())
	A = list(map(int, input().split()))
	A_cnt = Counter(A)
	ans = 0
	for (key, value) in list(A_cnt.items()):
		if key == value:
			pass
		elif key > value:
			ans += value
		else:
			ans += value - key
	print(ans)

def __starting_point():
	main()
__starting_point()


import collections as c
(N, *A) = map(int, open(0).read().split())
A = c.Counter(A)
ans = 0
for (a, n) in A.items():
	if a < n:
		ans += n - a
	elif a > n:
		ans += n
print(ans)


from collections import Counter
n = int(input())
L = Counter(list(map(int, input().split())))
ans = 0
for i in L:
	if i != L[i]:
		if L[i] - i > 0:
			ans = ans + L[i] - i
		else:
			ans += L[i]
print(ans)


N = int(input())
A = list(map(int, input().split()))
d = dict()
for i in range(N):
	if d.get(A[i]) is None:
		d[A[i]] = 1
	else:
		d[A[i]] += 1
ans = 0
for (key, value) in list(d.items()):
	if key <= value:
		ans += value - key
	else:
		ans += value
print(ans)


from collections import Counter
n = int(input())
c = Counter(map(int, input().split()))
ans = 0
for i in c:
	if c[i] > i:
		ans += c[i] - i
	elif c[i] < i:
		ans += c[i]
print(ans)


import collections
n = int(input())
a = list(map(int, input().split()))
a_cnt = collections.Counter(a)
cnt = 0
for item in a_cnt.items():
	if item[0] < item[1]:
		cnt += item[1] - item[0]
	elif item[0] > item[1]:
		cnt += item[1]
print(cnt)


import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan2, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return list(map(int, input().split()))

def LIST():
	return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	N = INT()
	li = LIST()
	A = defaultdict(int)
	for i in li:
		A[i] += 1
	cnt = 0
	for i in list(A.keys()):
		if i < A[i]:
			cnt += A[i] - i
		elif i > A[i]:
			cnt += A[i]
	print(cnt)

def __starting_point():
	main()
__starting_point()


N = int(input())
A = list(map(int, input().split()))
ans = 0
dict = {}
for i in range(N):
	if A[i] in dict:
		dict[A[i]] += 1
	else:
		dict[A[i]] = 1
for x in dict:
	if x > dict[x]:
		ans += dict[x]
	else:
		ans += dict[x] - x
print(ans)


n = int(input())
a = list(map(int, input().split()))
s = set(a)
d = {}
for i in s:
	d[i] = 0
for i in a:
	d[i] += 1
ans = 0
for i in d:
	c = d[i]
	if c < i:
		ans += c
	elif c >= i:
		ans += c - i
print(ans)


import collections as c
n = int(input())
s = list(map(int, input().split()))
s = c.Counter(s)
ans = 0
for i in s.items():
	a = i[0]
	b = i[1]
	if b < a:
		ans += b
	else:
		ans += b - a
print(ans)


import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
ans = 0
for k in c.keys():
	if k > c[k]:
		ans += c[k]
	elif k < c[k]:
		ans += c[k] - k
print(ans)


import sys
import math
from collections import Counter
inint = lambda : int(sys.stdin.readline())
inintm = lambda : map(int, sys.stdin.readline().split())
inintl = lambda : list(inintm())
instrm = lambda : map(str, sys.stdin.readline().split())
instrl = lambda : list(instrm())
n = inint()
A = inintl()
C = Counter(A)
ans = 0
for c in C:
	if c > C[c]:
		ans += C[c]
	elif c < C[c]:
		ans += C[c] - c
print(ans)


from collections import Counter
N = input()
A = list(map(int, input().split()))
counter = Counter(A)
cnt = 0
for (k, v) in counter.items():
	if v < k:
		cnt += v
	elif v > k:
		cnt += v - k
print(cnt)


N = int(input())
a = list(map(int, input().split()))
a.sort()
c = 1
ans = 0
for i in range(N - 1):
	if a[i] == a[i + 1]:
		c += 1
		if c > a[i]:
			ans += 1
	elif c < a[i]:
		ans += c
		c = 1
	else:
		c = 1
if c < a[N - 1]:
	ans += c
print(ans)


import sys
from io import StringIO
import unittest
from collections import Counter

class TestClass(unittest.TestCase):

	def assertIO(self, input, output):
		(stdout, stdin) = (sys.stdout, sys.stdin)
		(sys.stdout, sys.stdin) = (StringIO(), StringIO(input))
		resolve()
		sys.stdout.seek(0)
		out = sys.stdout.read()[:-1]
		(sys.stdout, sys.stdin) = (stdout, stdin)
		self.assertEqual(out, output)

	def test_入力例_1(self):
		input = '4\n3 3 3 3'
		output = '1'
		self.assertIO(input, output)

	def test_入力例_2(self):
		input = '5\n2 4 1 4 2'
		output = '2'
		self.assertIO(input, output)

	def test_入力例_3(self):
		input = '6\n1 2 2 3 3 3'
		output = '0'
		self.assertIO(input, output)

	def test_入力例_4(self):
		input = '1\n1000000000'
		output = '1'
		self.assertIO(input, output)

	def test_入力例_5(self):
		input = '8\n2 7 1 8 2 8 1 8'
		output = '5'
		self.assertIO(input, output)

def resolve():
	N = int(input())
	A = tuple(map(int, input().split()))
	C = Counter(A)
	ans = 0
	for (k, v) in list(C.items()):
		if v > k:
			ans += v - k
		elif v < k:
			ans += v
	print(ans)

def __starting_point():
	resolve()
__starting_point()


N = int(input())
A = list(map(int, input().split()))
ans = 0
A.sort()
count = 0
m = 0
for i in range(N):
	if count == 0:
		m = A[i]
		count += 1
	elif A[i] == m:
		count += 1
	else:
		if m > count:
			ans += count
		else:
			ans += count - m
		count = 1
		m = A[i]
if m > count:
	ans += count
else:
	ans += count - m
print(ans)


from collections import Counter
n = int(input())
a = Counter(list(map(int, input().split())))
cnt = 0
for (x, y) in a.items():
	if x == y:
		continue
	if x > y:
		cnt += y
	else:
		cnt += y - x
print(cnt)


import collections
n = int(input())
a = list(map(int, input().split()))
l = list(set(a))
m = collections.Counter(a)
ans = 0
for i in range(len(l)):
	if m[l[i]] < l[i]:
		ans += m[l[i]]
	else:
		ans += m[l[i]] - l[i]
print(ans)


n = int(input())
a = list(map(int, input().split()))
d = dict()
for i in a:
	if i not in d:
		d[i] = 1
	else:
		d[i] += 1
count = 0
for (key, value) in list(d.items()):
	if int(key) > value:
		count += int(value)
	elif int(key) < value:
		count += value - int(key)
print(count)


import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
INPUT = lambda : sys.stdin.readline().rstrip()
INT = lambda : int(INPUT())
MAP = lambda : list(map(int, INPUT().split()))
S_MAP = lambda : list(map(str, INPUT().split()))
LIST = lambda : list(map(int, INPUT().split()))
S_LIST = lambda : list(map(str, INPUT().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()
A_c = Counter(A)
ans = 0
for (k, v) in zip(list(A_c.keys()), list(A_c.values())):
	if k < v:
		ans += v - k
	elif k > v:
		ans += v
print(ans)


n = int(input())
alist = list(map(int, input().split()))
from collections import Counter
adic = Counter(alist)
count = 0
for (k, v) in adic.items():
	if int(k) <= v:
		count += v - int(k)
	else:
		count += v
print(count)


def count(list):
	dict = {}
	for i in range(len(list)):
		dict[list[i]] = dict.get(list[i], 0) + 1
	return dict
n = int(input())
a = list(map(int, input().split()))
dic = count(a)
ans = 0
for (i, x) in dic.items():
	differ = x - i
	if differ > 0:
		ans += differ
	elif differ < 0:
		ans += x
print(ans)


N = int(input())
a = [int(s) for s in input().split()]
p = {}
for b in a:
	if b in p:
		p[b] += 1
	else:
		p[b] = 1
ans = 0
for k in p:
	if k > p[k]:
		ans += p[k]
	elif k < p[k]:
		ans += p[k] - k
print(ans)


import collections as c
input()
print(sum((j if i > j else j - i for (i, j) in c.Counter(map(int, input().split())).items())))


from collections import Counter
ans = 0
_ = input()
a = list(map(int, input().split()))
for (k, v) in Counter(a).items():
	if k > v:
		ans += v
	elif k < v:
		ans += v - k
print(ans)


N = int(input())
a = list(map(int, input().split()))
a = sorted(a)
l = a[0]
cnt = 0
b = []
for i in range(N):
	if a[i] == l:
		cnt += 1
	else:
		b.append([l, cnt])
		l = a[i]
		cnt = 1
if cnt > 0:
	b.append([l, cnt])
ans = 0
for i in range(len(b)):
	if b[i][0] > b[i][1]:
		ans += b[i][1]
	else:
		ans += b[i][1] - b[i][0]
print(ans)


n = int(input())
a = list(map(int, input().split()))
import collections
a = collections.Counter(a)
ans = 0
for (i, j) in list(a.items()):
	if i > j:
		ans += j
	else:
		ans += abs(i - j)
print(ans)


from collections import Counter
(N, *A) = list(map(int, open(0).read().split()))
cnt = Counter(A)
ans = 0
for (k, v) in list(cnt.items()):
	if k > v:
		ans += v
	else:
		ans += v - k
print(ans)


from collections import Counter
N = int(input())
D = list(map(int, input().split()))
CD = Counter(D)
CD = list(CD.items())
count = 0
for i in range(len(CD)):
	if CD[i][0] < CD[i][1]:
		count = count + CD[i][1] - CD[i][0]
	elif CD[i][0] > CD[i][1]:
		count = count + CD[i][1]
print(count)


n = int(input())
al = list(map(int, input().split()))
ans = 0
dic = {}
for a in al:
	dic[a] = dic.get(a, 0) + 1
for (k, v) in dic.items():
	if k == v:
		pass
	elif k < v:
		ans += v - k
	else:
		ans += v
print(ans)


from collections import Counter
n = int(input())
A = list(map(int, input().split()))
cnt_A = Counter(A)
ans = 0
for (k, v) in cnt_A.items():
	if v - k >= 0:
		ans += v - k
	else:
		ans += v
print(ans)


import math
from collections import Counter
from itertools import product
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(map(int, input().split()))
n = ii()
a = li()
cnt = Counter(a)
ans = 0
for (i, j) in cnt.items():
	if i > j:
		ans += j
	else:
		ans += j - i
print(ans)


import sys

def solve(N: int, a: 'List[int]'):
	from collections import Counter
	ans = 0
	for (k, v) in list(Counter(a).items()):
		ans += v - k if v >= k else v
	return ans

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	N = int(next(tokens))
	a = [int(next(tokens)) for _ in range(N)]
	print(solve(N, a))

def test():
	import doctest
	doctest.testmod()

def __starting_point():
	main()
__starting_point()


n = int(input())
a = list(map(int, input().split()))
cnt = dict()
for ai in a:
	if ai not in list(cnt.keys()):
		cnt[ai] = 1
	else:
		cnt[ai] += 1
ans = 0
for k in list(cnt.keys()):
	if cnt[k] > k:
		ans += cnt[k] - k
	elif cnt[k] < k:
		ans += cnt[k]
print(ans)


import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
cnt = 0
for (k, v) in list(c.items()):
	cnt += min(v - k, v) if v - k >= 0 else v
print(cnt)


from math import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import bisect
import heapq
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7
INF = float('inf')
from sys import stdin
readline = stdin.readline

def readInts():
	return list(map(int, readline().split()))

def readTuples():
	return tuple(map(int, readline().split()))

def I():
	return int(readline())
n = I()
Count = Counter(readInts())
ans = 0
for (k, v) in list(Count.items()):
	if k < v:
		ans += v - k
	if v < k:
		ans += v
print(ans)


from collections import Counter
n = int(input())
aa = Counter(map(int, input().split()))
ans = 0
for (k, v) in aa.items():
	if k < v:
		ans += v - k
	elif k > v:
		ans += v
print(ans)


from collections import Counter
_ = input()
a = [int(i) for i in input().split()]
ans = 0
for (k, v) in Counter(a).items():
	if k < v:
		ans += v - k
	elif v < k:
		ans += v
else:
	print(ans)


import collections
n = int(input())
aa = list(map(int, input().split()))
cc = collections.Counter(aa)
cnt = 0
for c in list(cc.items()):
	if c[0] > c[1]:
		cnt += c[1]
	elif c[0] == c[1]:
		continue
	elif c[0] < c[1]:
		cnt += c[1] - c[0]
print(cnt)


import collections
N = int(input())
lsA = list(map(int, input().split()))
counterA = collections.Counter(lsA)
ans = 0
for i in counterA.keys():
	if i == counterA[i]:
		continue
	if i < counterA[i]:
		ans += counterA[i] - i
	elif i > counterA[i]:
		ans += counterA[i]
print(ans)


n = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
	d[a] = d.get(a, 0) + 1
ans = 0
for a in d:
	if d[a] > a:
		ans += d[a] - a
	elif d[a] < a:
		ans += d[a]
print(ans)


import collections
N = int(input())
a = list(map(int, input().split()))
ans = 0
aa = collections.Counter(a).most_common()
for (i, j) in aa:
	if i > j:
		ans += j
	if i < j:
		ans += j - i
print(ans)


from collections import Counter
N = int(input())
C = Counter(map(int, input().split()))
ans = 0
for i in C:
	if C[i] > i:
		ans += C[i] - i
	elif C[i] < i:
		ans += C[i]
print(ans)


from collections import Counter
n = int(input())
al = list(map(int, input().split()))
c = Counter(al)
ans = 0
for (k, v) in list(c.items()):
	if k == v:
		continue
	elif k > v:
		ans += v
	else:
		ans += v - k
print(ans)


N = int(input())
A = list(map(int, input().split()))
dic = {}
for a in A:
	if a in dic:
		dic[a] += 1
	else:
		dic[a] = 1
ans = 0
for key in dic:
	if dic[key] != key:
		if dic[key] > key:
			ans += dic[key] - key
		else:
			ans += dic[key]
print(ans)


N = int(input())
a = list(map(int, input().split()))
a_dic = {}
for i in range(N):
	if a[i] not in a_dic.keys():
		a_dic[a[i]] = 1
	else:
		a_dic[a[i]] += 1
ans = 0
for i in a_dic.keys():
	if a_dic[i] >= i:
		ans += a_dic[i] - i
	elif a_dic[i] < i:
		ans += a_dic[i]
print(ans)


N = int(input())
lst = list(map(int, input().split()))
lst.sort()
freq = {}
for i in lst:
	if i in freq:
		freq[i] += 1
	else:
		freq[i] = 1
ans = 0
for (key, value) in freq.items():
	if key > value:
		ans += value
	elif key < value:
		ans += abs(key - value)
print(ans)


n = int(input())
a = list(map(int, input().split()))
hindo = dict()
for i in a:
	if i in hindo:
		hindo[i] += 1
	else:
		hindo[i] = 1
ans = 0
for (num, cnt) in hindo.items():
	if num == cnt:
		continue
	elif num > cnt:
		ans += cnt
	else:
		ans += cnt - num
print(ans)


import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
ans = 0
for (k, v) in list(c.items()):
	if k > v:
		ans += v
	if k < v:
		ans += v - k
print(ans)


N = int(input())
a = list(map(int, input().split()))
a.sort()
a.append(0)
i = 0
ans = 0
while i < N:
	x = a[i]
	count = 0
	while a[i] == x:
		i += 1
		count += 1
	if count < x:
		ans += count
	else:
		ans += count - x
print(ans)


from collections import Counter
input()
a = Counter(map(int, input().split()))
print(sum((v - k if k <= v else v for (k, v) in a.items())))


import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
ans = 0
for i in c.keys():
	if c[i] >= i:
		ans += c[i] - i
	else:
		ans += c[i]
print(ans)


N = input()
A = sorted([int(x) for x in input().split()])
import bisect as bs
ans = 0
f = lambda X, x: bs.bisect_right(X, x) - bs.bisect_left(X, x)
for a in set(A):
	cnt = f(A, a)
	if cnt < a:
		ans += cnt
	else:
		ans += cnt - a
print(ans)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = Counter(a)
ans = 0
for i in set(a):
	if b[i] < i:
		ans += b[i]
	else:
		ans += b[i] - i
print(ans)


import collections
n = int(input())
A = list(map(int, input().split()))
C = collections.Counter(A)
ans = 0
for (k, v) in C.items():
	if k == v:
		continue
	elif k < v:
		ans += v - k
	else:
		ans += v
print(ans)


n = int(input())
a = list(map(int, input().split()))
values = {}
cnt = n
for i in range(n):
	if a[i] in values:
		values[a[i]] += 1
	else:
		values[a[i]] = 1
	if values[a[i]] == a[i]:
		cnt -= a[i]
print(cnt)


from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
D = defaultdict(int)
for a in A:
	D[a] += 1
ans = 0
for (a, x) in D.items():
	if x >= a:
		ans += x - a
	else:
		ans += x
print(ans)


n = int(input())
a = list(map(int, input().split()))
num_map = dict()
for i in range(n):
	if a[i] not in num_map:
		num_map[a[i]] = 1
	else:
		num_map[a[i]] += 1
res = 0
for (key, value) in list(num_map.items()):
	if key <= value:
		res += value - key
	else:
		res += value
print(res)


def main():
	n = int(input())
	a_lst = list(map(int, input().split()))
	a_lst.sort()
	a_set_lst = list(set(a_lst))
	a_set_lst.sort()
	count_lst = []
	count = 1
	if n == 1:
		count_lst.append(count)
	else:
		for i in range(n - 1):
			a1 = a_lst[i]
			a2 = a_lst[i + 1]
			if a1 == a2:
				count += 1
				if i == n - 2:
					count_lst.append(count)
			else:
				count_lst.append(count)
				count = 1
		if a_lst[-1] != a_lst[-2]:
			count_lst.append(count)
	minimum = 0
	for i in range(len(a_set_lst)):
		number = a_set_lst[i]
		count = count_lst[i]
		if count < number:
			minimum += count
		else:
			minimum += count - number
	print(minimum)

def __starting_point():
	main()
__starting_point()


from collections import Counter
N = int(input())
a = list(map(int, input().split()))
a_counter = Counter(a)
ans = 0
if N == 1 and a[0] != 1:
	print(1)
	return
elif N == 1 and a[0] == 1:
	print(0)
	return
for i in a_counter.items():
	key = i[0]
	value = i[1]
	if key == value:
		pass
	elif key < value:
		ans = ans + (value - key)
	else:
		ans = ans + value
print(ans)


from collections import Counter
n = int(input())
a = Counter(list(map(int, input().split())))
ans = 0
for (x, y) in a.items():
	if x < y:
		ans += y - x
	elif y < x:
		ans += y
print(ans)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a = Counter(a).most_common()
num = 0
for (i, j) in a:
	if i < j:
		num += j - i
	elif j < i:
		num += j
print(num)


from collections import Counter
import sys
sys.setrecursionlimit(10 ** 6)
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
ans = 0
for i in sorted(c.keys()):
	if c[i] < i:
		ans += c[i]
	elif c[i] == i:
		continue
	elif c[i] > i:
		ans += c[i] - i
print(ans)


import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop
INPUT = lambda : sys.stdin.readline().rstrip()
INT = lambda : int(INPUT())
MAP = lambda : list(map(int, INPUT().split()))
S_MAP = lambda : list(map(str, INPUT().split()))
LIST = lambda : list(map(int, INPUT().split()))
S_LIST = lambda : list(map(str, INPUT().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	N = INT()
	A = LIST()
	c = Counter(A)
	ans = 0
	for (k, v) in list(c.items()):
		if k < v:
			ans += v - k
		elif k > v:
			ans += v
	print(ans)

def __starting_point():
	main()
__starting_point()


N = int(input())
A = [int(x) for x in input().split()]
d = [0] * N
ans = 0
for a in A:
	if a > N:
		ans += 1
	else:
		d[a - 1] += 1
for i in range(N):
	if d[i] > 0:
		if d[i] > i + 1:
			ans += d[i] - (i + 1)
		if d[i] < i + 1:
			ans += d[i]
print(ans)


from collections import Counter
from itertools import starmap

def main():
	N = input()
	A = list(map(int, input().split()))
	count = Counter(A)
	remove = lambda x, y: y - x if y >= x else y
	ans = sum(starmap(remove, count.items()))
	print(ans)
main()


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
flag = [False] * n
res = 0
for i in range(n):
	if flag[i]:
		continue
	c = 0
	j = i
	while a[i] == a[j]:
		c += 1
		flag[j] = True
		j += 1
		if j == n:
			break
	if c == a[i] or c == 0:
		continue
	elif c < a[i]:
		res += c
	else:
		res += c - a[i]
print(res)