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.

Starter code:

Solutions:
    
for __ in range(int(input())):
    n,m=map(int,input().split())
    arr=list(map(int,input().split()))
    s=set(arr)
    mex=-1
    ele=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)
    
    
    


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())
    ar=[int(x) for x in input().split()]
    ar.sort()
    f=0
    j=1
    # v=[]
    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
        else:
            if 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)
                
                
            
        
    
    
        
    
    

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))

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))

# cook your dish here
import bisect
t = int(input())
for _ in range(t):
    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)
    else:
        if m in seti:
            print(n-arr.count(m))
        else:
            print(n)
            

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)



# cook your dish here
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)

# cook your dish here
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])
    


# cook your dish here
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])
    


# cook your dish here
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])
    


# cook your dish here
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])
    


# cook your dish here
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])
    


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)
    else:
        if 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())
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())
while t:
    n,m=map(int,input().split())
    a=list(map(int,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


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

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())
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
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))


'''

                            Online Python Compiler.
                Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.

'''
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)

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)

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])