Chef has a sequence of positive integers $A_1, A_2, \ldots, A_N$. He wants to choose some elements of this sequence (possibly none or all of them) and compute their MEX, i.e. the smallest positive integer which does not occur among the chosen elements. For example, the MEX of $[1, 2, 4]$ is $3$.
Help Chef find the largest number of elements of the sequence $A$ which he can choose such that their MEX is equal to $M$, or determine that it is impossible.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains two space-separated integers $N$ and $M$.
- The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$.

-----Output-----
For each test case, print a single line containing one integer ― the maximum number of elements Chef can choose, or $-1$ if he cannot choose elements in such a way that their MEX is $M$.

-----Constraints-----
- $1 \le T \le 100$
- $2 \le M \le N \le 10^5$
- $1 \le A_i \le 10^9$ for each valid $i$
- the sum of $N$ over all test cases does not exceed $10^6$

-----Example Input-----
1
3 3
1 2 4

-----Example Output-----
3

-----Explanation-----
Example case 1: The MEX of whole array is 3. Hence, we can choose all the elements.

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Constructive algorithms

Ad-hoc


Solutions:
from sys import stdin, stdout
from collections import Counter
input = stdin.readline

def binarySearch(arr, term, n):
	low = 0
	high = n - 1
	while high >= low:
		mid = (low + high) // 2
		if arr[mid] == term:
			return 1
		elif term < arr[mid]:
			high = mid - 1
		else:
			low = mid + 1
	return 0
t = int(input().strip())
for _ in range(t):
	(n, m) = list(map(int, input().strip().split()))
	arr = list(map(int, input().strip().split()))
	arr.sort()
	flag = 1
	for i in range(1, m):
		flag = binarySearch(arr, i, n)
		if flag == 0:
			break
	if flag == 0:
		print(-1)
		continue
	d1 = Counter(arr)
	value = d1.get(m, 0)
	print(n - value)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	array = list(map(int, input().split()))
	ans = len(array) - array.count(m)
	flag = 0
	array = list(set(array))
	array.sort()
	try:
		if array.index(m - 1) + 1 != m - 1:
			print(-1)
			flag = 1
	except:
		print(-1)
		flag = 1
	if flag == 0:
		print(ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	no = l.count(b)
	l = list(set(l))
	if len(l) < b - 1:
		print(-1)
	elif l[b - 2] != b - 1:
		print(-1)
	else:
		print(a - no)


import sys
from collections import Counter, defaultdict, deque
from math import gcd, sqrt, ceil

def li():
	return [int(i) for i in sys.stdin.readline().split()]

def si():
	return sys.stdin.readline().split()

def ii():
	return int(sys.stdin.readline())

def ip():
	return input()
for tastcas in range(int(input())):
	(n, m) = li()
	a = li()
	sa = set(a)
	trumex = 1
	while trumex in sa:
		trumex += 1
	if m == trumex:
		print(n)
	elif m < trumex:
		x = a.count(m)
		print(n - x)
	else:
		print(-1)


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
for _ in range(RI()):
	(n, m) = RMI()
	vals = RMI()
	has = vals.count(m)
	answer = n - has
	sets = sorted(set(vals))
	for y in range(1, m, 1):
		if sets[y - 1] != y:
			answer = -1
			break
	print(answer)


t = int(input())
while t:
	(n, m) = (int(o) for o in input().split())
	a = [int(o) for o in input().split()]
	a.sort()
	j = 1
	cm = 0
	for i in range(n):
		if a[i] > j:
			cm = a[i]
			break
		else:
			j += 1
	if i == n - 1 and cm == 0:
		cm = a[n - 1] + 1
	if cm == m:
		print(n)
	elif cm < m:
		print(-1)
	else:
		c = 0
		for i in range(n):
			if a[i] != m:
				c += 1
		print(c)
	t -= 1


T = int(input())
for i in range(T):
	(N, M) = map(lambda x: int(x), str(input()).split(' '))
	A = list(map(lambda x: int(x), str(input()).split(' ')))
	dictone = {}
	for j in range(N):
		dictone[A[j]] = dictone.get(A[j], 0) + 1
	dictwo = list(dictone.items())
	dictwo.sort(key=lambda x: x[0])
	nums = []
	minval = -1
	flag = 1
	cursor = 0
	j = 0
	while j < len(dictwo):
		if dictwo[j][0] != cursor + 1:
			minval = cursor + 1
			flag = 0
			break
		else:
			cursor = cursor + 1
			nums.append(dictwo[j][1])
		j = j + 1
	if flag:
		minval = dictwo[-1][0] + 1
	if M < minval:
		print(len(A) - nums[M - 1])
	elif M == minval:
		print(len(A))
	else:
		print(-1)


import bisect
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	lis = list(map(int, input().split()))
	if n < 0:
		print(0)
	else:
		di = dict()
		for i in lis:
			di[i] = di.get(i, 0) + 1
		lis = sorted(list(set(lis)))
		cnt = 0
		ans = 0
		ind = bisect.bisect_left(lis, m)
		for i in range(ind):
			if i + 1 == lis[i]:
				cnt += 1
			ans += di[lis[i]]
		if cnt != m - 1:
			print(-1)
		else:
			for i in range(len(lis)):
				ans += di[lis[i]] if lis[i] > m else 0
			print(ans)


for z in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	x = 1
	j = 0
	a.sort()
	for i in range(n):
		if a[i] == m:
			continue
		if a[i] == x:
			x += 1
		j += 1
	if x != m or j == 0:
		print(-1)
	else:
		print(j)


tc = int(input())
for _ in range(tc):
	(N, M) = map(int, input().split())
	arr = list(map(int, input().split()))
	curr_mex = 1
	arr.sort()
	for i in range(N):
		if arr[i] == curr_mex:
			curr_mex += 1
	if curr_mex == M:
		print(N)
	elif curr_mex < M:
		print(-1)
	else:
		cnt = 0
		for x in arr:
			if x == M:
				cnt += 1
		print(N - cnt)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	d = dict()
	for el in a:
		if el not in d:
			d[el] = 1
		else:
			d[el] += 1
	mex = len(a) + 1
	for i in range(len(a)):
		if i + 1 not in d:
			mex = i + 1
			break
	if m < mex:
		print(len(a) - d[m])
	elif m == mex:
		print(len(a))
	else:
		print(-1)


t = int(input())
for i in range(t):
	c = 1
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	a = set(A)
	j = 1
	while j < m and j in a:
		j += 1
	if j != m:
		print(-1)
	else:
		print(n - A.count(m))


from collections import Counter
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	ac = Counter(a)
	al = list(ac.keys())
	al.sort()
	finlist = []
	for i in range(m - 1):
		if i + 1 in ac:
			finlist.append(i + 1)
	if len(finlist) == m - 1:
		if m in ac:
			print(n - ac[m])
		else:
			print(n)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().strip().split()))
	list1 = list(map(int, input().strip().split()))
	count = list1.count(m)
	set1 = set(list1)
	list2 = list(set1)
	if len(list2) <= m - 2:
		print(-1)
	elif list2[m - 2] != m - 1:
		print(-1)
	else:
		print(n - count)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = [int(x) for x in input().split()]
	f = [0] * (m + 1)
	for i in range(n):
		if l[i] <= m:
			f[l[i]] += 1
	ans = True
	for i in range(m - 1, 0, -1):
		if f[i] == 0:
			ans = False
			break
	if ans:
		print(n - f[m])
	else:
		print(-1)


T = int(input())
for _ in range(T):
	(N, M) = map(int, input().split())
	A = list(map(int, input().split()))
	As = set(A)
	for i in range(1, len(A) + 2):
		if i not in As:
			mex = i
			break
	if mex < M:
		print(-1)
		continue
	c = len([i for i in A if i == M])
	print(len(A) - c)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	less = []
	(ans1, ans2) = (0, 0)
	for i in range(n):
		if l[i] < m:
			ans1 += 1
			less.append(l[i])
		elif l[i] > m:
			ans2 += 1
	if len(set(less)) == m - 1:
		print(ans1 + ans2)
	else:
		print(-1)


for tc in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	try:
		mIndex = arr.index(m)
	except:
		mIndex = -1
	if mIndex != -1:
		beforeArr = list(set(arr[:mIndex]))
		if beforeArr == list(range(1, m)):
			print(len(arr) - arr.count(m))
		else:
			print(-1)
	else:
		try:
			oneBeforeMIndex = arr.index(m - 1)
		except:
			oneBeforeMIndex = -1
		if oneBeforeMIndex != -1:
			beforeArr = list(set(arr[:oneBeforeMIndex + 1]))
			if beforeArr == list(range(1, m)):
				print(len(arr))
			else:
				print(-1)
		else:
			print(-1)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = set(arr)
	mex = -1
	for i in range(1, n + 1):
		if i not in s:
			mex = i
			break
	if m > mex:
		print(-1)
	elif m == mex:
		print(n)
	else:
		c = arr.count(m)
		print(n - c)


from bisect import bisect_left as lower_bound
from bisect import bisect_right as upper_bound
T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	flag = True
	index_l = lower_bound(a, m)
	index_r = upper_bound(a, m)
	check1 = set(a[:index_l])
	check2 = set([i for i in range(1, m)])
	if check1 != check2:
		print(-1)
	else:
		n1 = a.count(m)
		print(n - n1)


import bisect
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	a = bisect.bisect(l, m)
	s = list(set(l[0:a]))
	if len(s) == 0:
		if m == 1:
			if m in l:
				print(len(l) - l.count(m))
			else:
				print(n)
		else:
			print(-1)
	else:
		s.sort()
		a = s[len(s) - 1]
		if s == list(range(1, a + 1)):
			if m in l:
				print(len(l) - l.count(m))
			else:
				print(n)
		else:
			print(-1)


from sys import stdin

def sin():
	return stdin.readline()
for _ in range(int(sin())):
	(n, m) = map(int, sin().split())
	l = list(map(int, sin().split(' ')))
	g = [0] * max(l) * 2
	for i in l:
		g[i - 1] = 1
	p = g.index(0) + 1
	if p == m:
		print(n)
	elif p < m:
		print(-1)
	else:
		print(n - l.count(m))


def main():
	(n, m) = [int(x) for x in input().split()]
	l = [int(X) for X in input().split()]
	ls = set(l)
	f = 1
	for i in range(1, m):
		if i not in ls:
			f = 0
			break
	if f == 0:
		print(-1)
	elif m in ls:
		print(n - l.count(m))
	else:
		print(n)

def __starting_point():
	for _ in range(int(input())):
		main()
__starting_point()


for _ in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	ls = [int(X) for X in input().split()]
	x = ls.count(m)
	ls2 = list(set(ls))
	if len(ls2) <= m - 2:
		print(-1)
	elif ls2[m - 2] != m - 1:
		print(-1)
	else:
		print(n - x)


t = int(input())
import sys
while t != 0:
	(n, m) = list(map(int, input().strip().split()))
	a = list(map(int, input().strip().split()))
	l = [0] * 100000
	mx = -1
	c = 0
	for i in a:
		if i > mx:
			mx = i
		l[i] += 1
	for i in range(1, mx + 1):
		if l[i] == 0:
			if i == m:
				print(n)
				c = 1
				break
			elif i < m:
				print(-1)
				c = 1
				break
			else:
				print(n - l[m])
				c = 1
				break
	if c == 0:
		if m == mx + 1:
			print(n)
		else:
			print('-1')
	t -= 1


from sys import stdin, stdout
from collections import defaultdict as D
try:
	for _ in range(int(input())):
		(n, m) = [int(i) for i in stdin.readline().split()]
		a = [int(i) for i in stdin.readline().split()]
		d = D(lambda : 0)
		for i in a:
			d[i] += 1
		k = 1
		for i in range(1, max(a) + 2):
			if d[i] == 0:
				k = i
				break
		if k == m:
			print(n)
		elif k < m:
			print(-1)
		elif k > m:
			print(n - d[m])
except:
	pass


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	st = set(arr)
	mex = -1
	for i in range(1, n + 1):
		if i not in st:
			mex = i
			break
	if mex == m:
		print(n)
	elif mex < m:
		print(-1)
	else:
		res = 0
		for i in arr:
			if i != m:
				res += 1
		print(res)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = n - l.count(m)
	l.sort()
	l = list(set(l))
	for i in range(1, m):
		if i != l[i - 1]:
			ans = -1
			break
	print(ans)


import sys

def main(n, m, a):
	a_set = set(a)
	a.sort()
	flag = 0
	for i in range(1, n + 1):
		if i >= m:
			break
		if i not in a_set:
			flag = 1
			break
	if flag == 0:
		temp = a.count(m)
		return n - temp
	else:
		return -1
t = int(sys.stdin.readline().rstrip())
for i in range(t):
	(n, m) = map(int, sys.stdin.readline().rstrip().split())
	a = list(map(int, sys.stdin.readline().rstrip().split()))
	print(main(n, m, a))


from collections import Counter
t = int(input())
ans = []
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	flag = True
	d = Counter(a)
	for i in range(1, m):
		if i not in d:
			flag = False
			break
	if flag:
		ans.append(n - d.get(m, 0))
	else:
		ans.append(-1)
for _ in ans:
	print(_)


def solve(arr, m):
	mex = -1
	d = list(set(arr))
	for i in range(len(d)):
		if d[i] != i + 1:
			mex = i + 1
			break
	if mex == -1:
		mex = max(arr) + 1
	if mex < m:
		ans = -1
	else:
		ans = 0
		for i in range(len(arr)):
			if arr[i] < m or arr[i] > m:
				ans += 1
	print(ans)
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = sorted(list(map(int, input().split())))
	solve(arr, m)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	b = list(map(int, input().split()))
	a = set(b)
	c = 0
	mini = min(a)
	for i in range(1, m):
		if i not in a:
			c = -1
			break
	if c == -1:
		print(-1)
	elif m in a:
		print(n - b.count(m))
	else:
		print(n)


t = int(input())
while t > 0:
	t -= 1
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	count = 0
	temp = [0] * (m + 1)
	for i in range(n):
		if a[i] == m:
			temp[a[i]] += 1
		elif a[i] > m:
			pass
		else:
			temp[a[i]] = 1
	for i in range(1, m):
		if temp[i] == 0:
			print(-1)
			break
		if i == m - 1:
			print(n - temp[-1])


test = int(input())
for _ in range(test):
	(N, M) = list(map(int, input().split()))
	numbers = list(map(int, input().split()))
	count = N - numbers.count(M)
	numbers.sort()
	numbers = list(set(numbers))
	for i in range(1, M):
		if i != numbers[i - 1]:
			count = -1
			break
	print(count)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ar = [int(x) for x in input().split()]
	ar.sort()
	f = 0
	j = 1
	if m == 1:
		c = ar.count(1)
		if n - c == 0:
			print(-1)
		else:
			print(n - c)
	else:
		if ar[0] == 1:
			prev = 1
			j = 2
			for i in range(1, n):
				if ar[i] < m:
					if ar[i] != prev and ar[i] == j:
						j += 1
						prev = ar[i]
					elif ar[i] != prev and ar[i] != j:
						f = 1
						break
					elif ar[i] == prev:
						continue
				else:
					break
		elif m != 1:
			f = 1
		if f == 1 or j != m:
			print(-1)
		else:
			c = ar.count(m)
			if n - c == 0:
				print(-1)
			else:
				print(n - c)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	(c, cnt) = (m - 1, 0)
	l1 = [0] * m
	for k in l:
		if k < m:
			if l1[k] == 0:
				l1[k] = 1
				c -= 1
			cnt += 1
		elif k > m:
			cnt += 1
	if c == 0:
		print(cnt)
	else:
		print(-1)


T = int(input())
for x in range(T):
	z = True
	(N, M) = map(int, input().split())
	lista = list(map(int, input().split()))
	r = lista.count(M)
	lista = list(set(lista))
	lista = sorted(lista)
	for y in range(1, M, 1):
		if lista[y - 1] != y:
			print(-1)
			z = False
			break
	if z:
		c = N - r
		print(c)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	seti = set(arr)
	f = 1
	for i in range(1, m):
		if i not in seti:
			f = 0
			break
	if f == 0:
		print(-1)
	elif m in seti:
		print(n - arr.count(m))
	else:
		print(n)


from bisect import bisect_left as lower_bound
from bisect import bisect_right as upper_bound
t = int(input())
for T in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	idx1 = lower_bound(l, m)
	idx2 = upper_bound(l, m)
	lower_num = 1
	flag = True
	for i in range(idx1):
		if i == 0 and l[i] != 1:
			flag = False
			break
		elif lower_num == l[i]:
			pass
		elif lower_num == l[i] - 1:
			lower_num = l[i]
	if lower_num != m - 1:
		flag = False
	if flag:
		print(idx1 + n - idx2)
	else:
		print(-1)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	mex = 1
	ans = 0
	for i in a:
		if i == m:
			continue
		elif i == mex:
			mex += 1
		ans += 1
	if mex != m:
		print('-1')
	elif ans == 0:
		print('-1')
	else:
		print(ans)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	nList = set(a)
	mex = 1
	while mex in nList:
		mex += 1
	if mex == m:
		print(len(a))
	elif mex < m:
		print(-1)
	elif mex > m:
		print(len(a) - a.count(m))


for _ in range(int(input())):
	(n, mex) = map(int, input().split())
	lstt = list(map(int, input().split()))
	leng = len(lstt)
	lstt.sort()
	lst = set(lstt)
	m = -1
	for i in range(1, n + 1):
		if i not in lst:
			m = i
			break
	if mex == m:
		print(leng)
	elif mex > m:
		print(-1)
	elif mex < m:
		print(leng - lstt.count(mex))


t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	l.sort()
	ans = 0
	c = 1
	for j in l:
		if j == m:
			continue
		if j == c:
			c += 1
		ans += 1
	if c != m:
		print(-1)
	elif ans == 0:
		print(-1)
	else:
		print(ans)


try:
	t = int(input())
	for i in range(0, t):
		(n, m) = map(int, input().split(' '))
		a = list(map(int, input().split(' ')))
		a.sort()
		s = set(a)
		for i in range(1, n + 1):
			if i not in s:
				op = i
				break
		if op == m:
			print(n)
		elif op > m:
			ol = a.count(m)
			print(n - ol)
		else:
			print(-1)
except:
	pass


t = int(input())
while t:
	(n, m) = map(int, input().split(' '))
	ls = [int(i) for i in input().split(' ')]
	ls.sort()
	count = 0
	mex = 1
	for i in range(n):
		if ls[i] == mex and mex + 1 <= m:
			mex += 1
			count += 1
		elif ls[i] != mex:
			count += 1
	if mex != m:
		print(-1)
	else:
		print(count)
	t -= 1


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	set_cont = set()
	for i in range(n):
		if k > arr[i]:
			set_cont.add(arr[i])
		else:
			break
	if len(set_cont) == k - 1:
		print(n - arr.count(k))
	else:
		print(-1)
	t -= 1


try:
	t = int(input())
	while t > 0:
		(n, m) = [int(i) for i in input().split()]
		a = [int(i) for i in input().split()]
		a.sort()
		mex = 1
		ans = 0
		for i in a:
			if i == m:
				continue
			if i == mex:
				mex = mex + 1
			ans = ans + 1
		if mex != m:
			print(-1)
		elif ans == 0:
			print(-1)
		else:
			print(ans)
		t = t + 1
except:
	pass


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = 0
	temp = [0] * (m - 1)
	for i in l:
		if i > m:
			ans += 1
		elif i < m:
			temp[i - 1] += 1
	flag = 1
	for i in range(m - 2, -1, -1):
		if temp[i] == 0:
			flag = 0
			break
		else:
			ans += temp[i]
	if flag == 0:
		print('-1')
	else:
		print(ans)


for T in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	count = [0] * n
	for key in a:
		try:
			count[key - 1] += 1
		except:
			pass
	a = list(set(a))
	a.sort()
	flag = True
	for i in range(len(a)):
		if a[i] != i + 1:
			flag = False
			mex = i + 1
			break
	if flag:
		mex = len(a) + 1
	if mex < m:
		print(-1)
	else:
		print(n - count[m - 1])


T = int(input())
for i in range(T):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	(mex, ans) = (1, 0)
	for j in arr:
		if j == m:
			continue
		if j == mex:
			mex += 1
		ans += 1
	if mex == m:
		print(ans)
	else:
		print(-1)


for _ in range(int(input())):
	(n, m) = [int(q) for q in input().split()]
	a = list(map(int, input().split()))
	x = n - a.count(m)
	a = list(set(a))
	a.sort()
	for i in range(1, m):
		if i != a[i - 1]:
			x = -1
			break
	print(x)


for _ in range(int(input())):
	(N, M) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	A.sort()
	s = 1
	x = 0
	for i in range(len(A)):
		if A[i] == s and A[i] != M:
			s += 1
		if A[i] != M:
			x += 1
	if s == M:
		print(x)
	else:
		print('-1')


def answer():
	c = [0] * (m + 1)
	for v in a:
		if v <= m:
			c[v] += 1
	for i in range(1, m):
		if c[i] == 0:
			return -1
	return n - c[m]
for T in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	print(answer())


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr.sort()
	ans = 0
	mex = 1
	for i in arr:
		if i == m:
			continue
		if i == mex:
			mex += 1
		ans += 1
	if mex != m:
		print(-1)
	elif ans == 0:
		print(-1)
	else:
		print(ans)


from sys import stdin, stdout
import math
from collections import Counter
import functools
import time
import bisect

def tr():
	return range(int(line()))

def sm():
	return map(int, line().split())

def ln():
	return list(sm())

def nl():
	return int(line())

def ssm():
	return map(str, line().split())

def line():
	return stdin.readline().rstrip()

def b(x):
	return bin(x).replace('0b', '')

def o(x):
	if type(x) != type(''):
		x = str(x)
	stdout.write(x + '\n')

def osp(x):
	if type(x) != type(''):
		x = str(x)
	stdout.write(x + ' ')

def ol(x):
	stdout.write(' '.join(map(str, x)))

def wline():
	return stdin.read().split()

def main():
	for _ in tr():
		(n, m) = sm()
		a = ln()
		b = set(a)
		possible = True
		for i in range(1, m):
			if i not in b:
				possible = False
				break
		if possible:
			if m in a:
				print(n - a.count(m))
			else:
				print(n)
		else:
			print(-1)
main()


def solve():
	(n, m) = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a = set(b)
	c = 0
	for i in range(1, m):
		if i not in a:
			c = -1
			break
	if c == -1:
		print(-1)
	elif m in a:
		print(n - b.count(m))
	else:
		print(n)
t = int(input())
while t != 0:
	solve()
	t -= 1


import sys, math, itertools, random, bisect
from collections import defaultdict
INF = 10 ** 18

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
mod = 10 ** 9 + 7
for _ in range(int(input())):
	(n, m) = get_ints()
	a = get_array()
	freq = defaultdict(int)
	for i in a:
		freq[i] += 1
	flag = True
	for i in range(1, m):
		if freq[i] == 0:
			flag = False
			break
	if not flag:
		print(-1)
	else:
		print(n - freq[m])


t = int(input())
for _ in range(t):
	(n, m) = list(map(lambda x: int(x), input().split()))
	s = list(map(lambda x: int(x), input().split()))
	freq_array = [0] * m
	if m > n:
		print(-1)
		continue
	for i in range(0, len(s)):
		if s[i] >= m:
			continue
		else:
			freq_array[s[i]] += 1
	total = 0
	flag = 0
	for i in range(1, len(freq_array)):
		if freq_array[i] == 0:
			print(-1)
			flag = 1
			break
		total += freq_array[i]
	count_m = 0
	if flag == 1:
		continue
	for i in range(0, len(s)):
		if s[i] == m:
			count_m += 1
	print(n - count_m)


import math
case = int(input())
for _ in range(case):
	(n, m) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	arr.sort()
	number = 1
	res = 0
	for i in range(n):
		if number == m:
			break
		if arr[i] > number:
			res = -1
			break
		if arr[i] == number:
			number += 1
	if res == -1:
		print(-1)
	else:
		for i in range(n):
			if arr[i] != m:
				res += 1
		print(res)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	k = 1000000000000000
	for i in range(1, n):
		if a[i] - 1 > a[i - 1]:
			k = a[i] - 1
			break
	if k == m:
		print(n)
	elif k < m:
		print(-1)
	else:
		print(n - a.count(m))