import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class Osmos {
    
    public static String caseString = "Case #?: ";
    
    public static String[] read(String file) throws Exception {
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line = null;
        List<String> arrayList = new ArrayList<String>();
        while((line = br.readLine()) != null)  {
            if(!line.trim().equalsIgnoreCase("")) {
                arrayList.add(line);
            }
        }
        return arrayList.toArray(new String[0]);
    }
    
    public static void write(String file, String[] content) throws Exception {
        BufferedWriter bw = new BufferedWriter(new PrintWriter(file));
        for (int i = 0; i < content.length; i++) {
            String caseS = caseString.replace("?", (i+1)+"");
            bw.append(caseS+content[i]+"\n");
        }
        bw.flush();
        bw.close();
    }
    
    public static void main(String[] args) throws Exception {
        String inputfile = "/Users/sumitkumar/Desktop/codejam/1/A-large-practice.in";
        String outputfile = "/Users/sumitkumar/Desktop/codejam/1/A-large-practice.out";
        String[] input = read(inputfile);
        int testCases = Integer.parseInt(input[0]);
        String[] output = new String[testCases];
        int counter = 1;
        System.out.println("testCases ::"+testCases);
        for (int i = 0; i < testCases; i++) {
            System.out.println(i);
            String [] line1 = input[counter++].split(" ");
            int yourBot = Integer.parseInt(line1[0]);
            int botsCount = Integer.parseInt(line1[1]);
            String [] botsString = input[counter++].split(" ");
            int [] bots = new int[botsCount];
            for (int j = 0; j < botsCount; j++) {
                bots[j] = Integer.parseInt(botsString[j]);
            }
            output[i] = solve(yourBot, bots, botsCount);
        } 
        write(outputfile, output);
    }
    
    private static String solve(int yourBot, int[] bots, int botsCount) {
        sort(bots, botsCount);
        int myBot = yourBot;
        int change = 0;
        int i = 0;
        for (i = 0; i < botsCount; i++) {
            if(myBot > bots[i]) {
                myBot += bots[i];
                continue;
            }
            if((2*myBot-1) > bots[i]) {
                myBot = 2*myBot-1 + bots[i];
                change++;
                continue;
            }
            break; 
        }
        int changesWithoutAddition = changesWithoutAddition(myBot, bots, i, botsCount);
        int changesWithAddition = -1;
        if(i < botsCount)
            changesWithAddition = changesWithAddition(myBot, bots, i, botsCount);
        int min = changesWithoutAddition;
        if(changesWithAddition >= 0) {
            min = (changesWithoutAddition < changesWithAddition) ? changesWithoutAddition : changesWithAddition;
        }
        change+=min;
        return change+"";
    }
    
    private static int changesWithoutAddition(int myBot, int bots[], int index, int botsCount) {
        System.out.println("changesWithoutAddition"+index);
        return botsCount-index;
    }
    private static int changesWithAddition(int myBot, int bots[], int index, int botsCount) {
        System.out.println("changesWithAddition"+index);
        int tempBot = myBot;
        int counter = 0;
        while(bots[index] >= tempBot) {
            tempBot = 2*tempBot - 1;
            counter++;
            if(counter >= (botsCount-index)) {
                return -1;
            }
        }
        for (int i = index; i < botsCount; i++) {
            if(tempBot > bots[i]) {
                tempBot += bots[i];
                continue;
            }
            if((2*tempBot-1) > bots[i]) {
                tempBot = 2*tempBot-1 + bots[i];
                counter++;
                continue;
            }
            int changesWithoutAddition = changesWithoutAddition(tempBot, bots, i, botsCount);
            int changesWithAddition = -1;
            if(i < botsCount)
                changesWithAddition = changesWithAddition(tempBot, bots, i, botsCount);
            int min = changesWithoutAddition;
            if(changesWithAddition >= 0) {
                min = (changesWithoutAddition < changesWithAddition) ? changesWithoutAddition : changesWithAddition;
            }
            counter+=min; 
            break;
        }
        return counter;
    }
    
    public static void sort(int[] values, int size) {
        if (values ==null || size==0){
          return ;
        }
        quicksort(0, size - 1, values);
      }

      private static void quicksort(int low, int high,int[] numbers) {
        int i = low, j = high;
        int pivot = numbers[low + (high-low)/2];
        while (i <= j) {
          while (numbers[i] < pivot) {
            i++;
          }
          while (numbers[j] > pivot) {
            j--;
          }
          if (i <= j) {
            exchange(i, j, numbers);
            i++;
            j--;
          }
        }
        if (low < j)
          quicksort(low, j, numbers);
        if (i < high)
          quicksort(i, high,numbers);
      }

      private static void exchange(int i, int j, int[] numbers) {
        int temp = numbers[i];
        numbers[i] = numbers[j];
        numbers[j] = temp;
      }

}
