description: Paprika loves permutations. She has an array a_1, a_2, ..., a_n. She wants to make the array a permutation of integers 1 to n.
  
  In order to achieve this goal, she can perform operations on the array. In each operation she can choose two integers i (1 ≤ i ≤ n) and x (x > 0), then perform a_i := a_i mod x (that is, replace a_i by the remainder of a_i divided by x). In different operations, the chosen i and x can be different.
  
  Determine the minimum number of operations needed to make the array a permutation of integers 1 to n. If it is impossible, output -1.
  
  A permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).
  
  Input
  
  Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
  
  The first line of each test case contains an integer n (1 ≤ n ≤ 10^5).
  
  The second line of each test case contains n integers a_1, a_2, ..., a_n. (1 ≤ a_i ≤ 10^9).
  
  It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.
  
  Output
  
  For each test case, output the minimum number of operations needed to make the array a permutation of integers 1 to n, or -1 if it is impossible.
  
  Example
  
  Input
  
  
  4
  2
  1 7
  3
  1 5 4
  4
  12345678 87654321 20211218 23571113
  9
  1 2 3 4 18 19 5 6 7
  
  
  Output
  
  
  1
  -1
  4
  2
  
  Note
  
  For the first test, the only possible sequence of operations which minimizes the number of operations is: 
  
    * Choose i=2, x=5. Perform a_2 := a_2 mod 5 = 2. 
  
  
  
  For the second test, it is impossible to obtain a permutation of integers from 1 to n.
solution: import java.io.*;
  import java.util.*;
  
  
  public class ComdeFormces {
  	public static void main(String[] args) throws Exception{
  		// TODO Auto-generated method stub
  		FastReader sc=new FastReader();
  		BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
  		int t=sc.nextInt();
  		while(t--!=0) {
  		int n=sc.nextInt();
  		 int a[]=new int[n];
  		 ArrayList<Integer> arr=new ArrayList<>();
  		 boolean vis[]=new boolean[n+1];
  		 for(int i=0;i<n;i++) {
  			 a[i]=sc.nextInt();
  			 if(a[i]>=1 && a[i]<=n && !vis[a[i]]) {
  				
  				 vis[a[i]]=true;
  			 }
  			 else {
  				 arr.add(a[i]);
  			 }
  		 }
  		 Collections.sort(arr);
  		boolean ans=true;
  		int cnt=0;
  		int ptr=0;
  		for(int i=1;i<=n;i++) {
  			if(!vis[i]) {
  				if(arr.get(ptr)-i>i){
  					cnt++;
  					ptr++;
  				}
  				else {
  					ans=false;
  					break;
  				}
  			}
  		}
  		if(ans)log.write(cnt+"");
  		else log.write("-1");
  		 
  		 
  		log.write("\n");
  		log.flush();
  		
  		}
  		
  	}
  static long find(int s,long a[]) {
  	if(s>=a.length)return -1;
  	long num=a[s];
  	for(int i=s;i<a.length;i+=2) {
  		num=gcd(num,a[i]);
  		if(num==1 || num==0)return -1;
  	}
  	return  num;
  }	
  static long gcd(long a,long b) {
  	if(b==0)return a;
  	else return gcd(b,a%b);
  }	
  static long factmod(long n,long mod,long img) {
  	if(n==0)return 1;
  	long ans=1;
  	long temp=1;
  	while(n--!=0) {
  		if(temp!=img) {
  		ans=((ans%mod)*((temp)%mod))%mod;
  		}
  		temp++;
  	}
  	return ans%mod;
  }	
  static long eval(ArrayList<Integer> a, int k) {
  	if(a.size()<1 )return 0;
  	int i=a.size()-1;
  	long ans=0;
  	while(i>=0) {
  		int temp=k;
  		int prev=0;
  		while(temp--!=0 && i>=0) {
  			ans+=Math.abs(a.get(i)-prev);
  			if(temp==0 || i==0)ans+=a.get(i);
  			prev=a.get(i);
  			i--;
  		}
  	}
  	return ans;
  }	
  static int bs(LinkedList<Long> a ,long num) {
  	int start=0;
  	int end=a.size()-1;
  	int tempAns=-1;
      while(start<=end) {
      	int mid=start+(end-start)/2;
      	if(a.get(mid)-num>num) {
      		tempAns=mid;
      		end=mid-1;
      	}
      	else if(a.get(mid)-num<=num)start=mid+1;
      
      }
      if(tempAns!=-1)return tempAns;
  	return -1;
  }	
  	
  	
  //utils	
  public static class trip{
  	int a,b,c;
  	public trip(int a,int b,int c) {
  		this.a=a;
  		this.b=b;
  		this.c=c;
  	}
  	public int compareTo(trip q) {
  		return this.c-q.c;
  	}
  }	
  	static void mergesort(long[] a,int start,int end) {
  		if(start>=end)return;
  		int mid=start+(end-start)/2;
  		mergesort(a,start,mid);
  		mergesort(a,mid+1,end);
  		merge(a,start,mid,end);
  	}
  	static void merge(long []a, int start,int mid,int end) {
  		int ptr1=start;
  		int ptr2=mid+1;
  		long b[]=new long[end-start+1];
  		int i=0;
  		while(ptr1<=mid && ptr2<=end) {
  			if(a[ptr1]<=a[ptr2]) {
  				b[i]=a[ptr1];
  				ptr1++;
  				i++;
  			}
  			else {
  				b[i]=a[ptr2];
  				ptr2++;
  				i++;
  			}
  		}
  		while(ptr1<=mid) {
  			b[i]=a[ptr1];
  			ptr1++;
  			i++;
  		}
  		while(ptr2<=end) {
  			b[i]=a[ptr2];
  			ptr2++;
  			i++;
  		}
  		for(int j=start;j<=end;j++) {
  			a[j]=b[j-start];
  		}
  	}
  	public static class FastReader {
  
  		BufferedReader b;
  		StringTokenizer s;
  		public FastReader() {
  			b=new BufferedReader(new InputStreamReader(System.in));
  		}
  		String next() {
  			while(s==null ||!s.hasMoreElements()) {
  				try {
  					s=new StringTokenizer(b.readLine());
  				}
  				catch(IOException e) {
  					e.printStackTrace();
  				}
  			}
  			return s.nextToken();
  		}
  		public int nextInt() {
  			return Integer.parseInt(next());
  		}
  		public long nextLong() {
  			return Long.parseLong(next());
  		}
  		public double nextDouble() {
  			return Double.parseDouble(next());
  		}
  		String nextLine() {
  			String str="";
  			try {
  				str=b.readLine();
  			}
  			catch(IOException e) {
  				e.printStackTrace();
  			}
  			return str;
  		}
  		boolean hasNext() {
  		    if (s != null && s.hasMoreTokens()) {
  		        return true;
  		    }
  		    String tmp;
  		    try {
  		        b.mark(1000);
  		        tmp = b.readLine();
  		        if (tmp == null) {
  		            return false;
  		        }
  		        b.reset();
  		    } catch (IOException e) {
  		        return false;
  		    }
  		    return true;
  		}
  }
  public static class pair{
  	int a,b;
  	public pair(int a,int b) {
  		this.a=a;
  		this.b=b;
  	}
  	public int compareTo(pair b) {
  		return this.a-b.a;
  	}
  }	
  }
  