Rearrange

Choose an ordering of the array, subtract elements from n in that order until n drops to 0 or below, and report the smallest achievable result.

Medium4GreedySortingInterviewNo attempts yetTime limit1sMemory limit512 MB

Problem

Here is the code of the getMin( ) function.

int getMin(int n, int arr[]){
    arr2 = rearrange(arr);
    for(int i = 0; i < arr2.length(); i = i+1){
        n = n-arr2[i];
        if (n <= 0) break;
    }
    return n;
}

getMin( ) takes an integer nn and an integer array arr, then calls rearrange( ). The rearrange( ) function takes an integer array and returns a new array. The new array holds the same members as the old one, and the position of each member may change.

How you write rearrange( ) is not judged. Choose the arrangement that makes the return value of getMin( ) as small as possible, and report that return value.

Input

The first line contains the number of test cases TT. (1T101 \le T \le 10)

Each test case takes two lines. The first line contains the integer nn and the length kk of the array arr, separated by a space. (0n100000 \le n \le 10000, 0k100000 \le k \le 10000) The second line contains kk integers, arr[0] through arr[k-1], separated by spaces. (0arr[i]10000000 \le \texttt{arr}[i] \le 1000000) When kk is 00, the second line is empty.

Output

For each test case, print the smallest value getMin( ) can return, one per line. The value may be negative.

Hint

In the second test case of the example, you send [70, 60, 80] to rearrange( ) and it returns [80, 70, 60]. Then 10080=20100 - 80 = 20 and 2070=5020 - 70 = -50, so the loop stops and the function returns 50-50. More than one arrangement can reach the minimum, but the value you print is that single minimum.