#K37992. Nth Smallest Distinct Number

    ID: 26099 Type: Default 1000ms 256MiB

Nth Smallest Distinct Number

Nth Smallest Distinct Number

You are given a list of integers for each test case. Your task is to find the nth smallest distinct number in the list. If the number of distinct elements is less than n, print \(-1\).

More formally, let \(A\) be the list of integers and let \(D\) be the set of distinct elements derived from \(A\), sorted in ascending order. You need to compute:

[ f(A, n) = \begin{cases} \text{the } n\text{-th smallest element of } D, & \text{if } |D| \ge n \ -1, & \text{otherwise} \end{cases} ]

For each test case, output the result on a separate line.

inputFormat

The first line contains an integer \(T\) \( (1 \le T \le 10^5) \) indicating the number of test cases. For each test case, the first line contains two integers \(n\) and \(m\) where \(n\) is the order of the smallest distinct number you need to find and \(m\) is the number of integers in the list. The next line contains \(m\) space-separated integers.

outputFormat

For each test case, output a single line containing the nth smallest distinct number from the list. If such a number does not exist, output -1.

## sample
3
3 5
4 2 5 1 3
7 3
-1 -2 -3
2 4
100000 99999 1000000 -100000
3

-1 99999

</p>