# frozen_string_literal: true N = gets.to_i A = gets.split.map(&:to_i) M = gets.to_i B = gets.split.map(&:to_i).sort.reverse ans = 100 A.permutation(N) do |list| box = B.dup index = 0 ok = false list.each_with_index do |a, i| while index < box.size if box[index] >= a box[index] -= a ok = true if i == list.size - 1 break else index += 1 end end end ans = [index, ans].min if ok end if ans == 100 puts '-1' else puts ans + 1 end