import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
from collections import defaultdict, deque

n = int(input())
a = list((int(i)) for i in input().split())
m = int(input())
b = list((int(i)) for i in input().split())
aa = deque(list(reversed(sorted(a))))
bb = list(reversed(sorted(b)))
count = 0
for bbb in bb:
    if aa:
        aa = deque(list(reversed(sorted(aa))))
        count += 1
        box = bbb
        for _ in range(len(aa)):
            v = aa.popleft()
            if box - v < 0:
                aa.append(v)
            else:
                box -= v
    else:
        break
if aa:
    print(-1)
else:
    print(count)