------
## 最终结论
```python
def min_divisions_to_fill_bag(t, test_cases):
    results = []
    
    for i in range(t):
        n, m, a = test_cases[i]
        count = 0
        needed = n
        
        # Count the number of boxes of each size
        box_count = {}
        for size in a:
            if size in box_count:
                box_count[size] += 1
            else:
                box_count[size] = 1
        
        # Sort the box sizes in descending order
        sorted_sizes = sorted(box_count.keys(), reverse=True)
        
        for size in sorted_sizes:
            while needed > 0 and size > 0:
                if needed >= size:
                    # Use this box to fill the bag
                    max_boxes = needed // size
                    use_boxes = min(max_boxes, box_count[size])
                    needed -= use_boxes * size
                    box_count[size] -= use_boxes
                else:
                    # We need to split this box to fit into the bag
                    if box_count[size] > 0:
                        # Split this box
                        count += 1
                        new_size = size // 2
                        box_count[new_size] = box_count.get(new_size, 0) + 2 * box_count[size]
                        box_count[size] = 0
            
            # If we've filled the bag completely, we can stop early
            if needed == 0:
                break
        
        if needed > 0:
            results.append(-1)
        else:
            results.append(count)
    
    return results

# Input handling part
import sys

input = sys.stdin.read
data = input().splitlines()
t = int(data[0])
test_cases = []

index = 1
for _ in range(t):
    n, m = map(int, data[index].split())
    a = list(map(int, data[index + 1].split()))
    test_cases.append((n, m, a))
    index += 2

results = min_divisions_to_fill_bag(t, test_cases)
for result in results:
    print(result)
```