input: from typing import List
  
  def min_boxes_to_refill_apples(apple: List[int], capacity: List[int]) -> int:
      """
      You are given an array apple of size n and an array capacity of size m.
  
      There are n packs where the i th pack contains apple[i] apples. There are m boxes as well, and the ith box has a capacity of capacity[i] apples.
  
      Return the minimum number of boxes you need to select to redistribute these n packs of apples into boxes.
  
      Note that, apples from the same pack can be distributed into different boxes.
  
      Examples:
      >>> apple = [1,3,2], capacity = [4,3,1,5,2]
      2
      >>> apple = [5,5,5], capacity = [2,4,2,7]
      4
  
      Constraints:
      1 <= n == apple.length <= 50
      1 <= m == capacity.length <= 50
      1 <= apple[i], capacity[i] <= 50
      The input is generated such that it's possible to redistribute packs of apples into boxes.
      """
  
output: 
      apple.sort(reverse=True)
      capacity.sort(reverse=True)
      
      boxes_used = 0
      i = 0
      
      for apples in apple:
          while apples > 0 and i < len(capacity):
              if capacity[i] > 0:
                  apples -= capacity[i]
                  boxes_used += 1
              i += 1
          if apples > 0:
              return -1
      
      return boxes_used
  