def ke(a):
    return(a[0], -a[1])
fin = open('cond.in')
n = int(fin.readline())
a = list(map(int, fin.readline().rstrip().split()))
m = int(fin.readline())
tmp = fin.read().rstrip().split('\n')
b = [list(map(int, tmp[i].split())) for i in range(m)]
a.sort(reverse=True)
b.sort(reverse=True, key=ke)
#print(a, b)
c = [b[0]]
for i in range(1, m):
    if b[i][0] < c[-1][0] and b[i][1] < c[-1][1]:
        c.append(b[i])
#print(c)
i = 0
k = 0
sum = 0
m = len(c)
#print(a)
while i < n:
    if k == m - 1 or c[k + 1][0] < a[i]:
        sum += c[k][1]
#        print(i, k)
        i += 1
    else:
        k += 1
print(sum, file=open('cond.out','w'))
