#include "bits/stdc++.h"
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
using ll = long long int;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
int t; cin >> t;
while (t--) {
int n; cin >> n;
vector<int> a(n);
for (int &x : a) cin >> x;
sort(begin(a), end(a));
a.erase(unique(begin(a), end(a)), end(a));
int mex = 0;
for (int x : a) {
if (x == mex) ++mex;
}
if (mex == 0) {
cout << a[0]-1 << '\n';
continue;
}
if (mex == 1) {
cout << -1 << '\n';
continue;
}
vector<int> longest(a.size());
longest[0] = 1;
int ans = 0;
for (int i = 1; i < a.size(); ++i) {
if (a[i] == a[i-1] + 1) longest[i] = longest[i-1] + 1;
else longest[i] = 1;
if (a[i] >= mex and longest[i] >= mex - 1 and (i+1 == a.size() or a[i]+1 < a[i+1])) ++ans;
}
cout << ans << '\n';
}
}