### constant

MAX_INT = 1 << 30

### main

m, n = gets.strip.split(' ').map(&:to_i)

pis = m.times.map{gets.strip.to_i}.sort{|a, b| b <=> a}
#p pis

psums = [0]
for i in (0...m)
  psums[i + 1] = psums[i] + pis[i]
end
#p psums

cis = []
eis = []

n.times do
  ci, ei = gets.strip.split(' ').map(&:to_i)
  cis << ci
  eis << ei
end
#p cis
#p eis

bps = (n + 1).times.map{(m + 1).times.map{MAX_INT}}
bps[0][0] = 0

for i in (1..n)
  ci = cis[i - 1]
  ei = eis[i - 1]
  for j in (0..m)
    j0 = [j - ci, 0].max
    bps[i][j] = [bps[i - 1][j], bps[i - 1][j0] + ei].min
  end
end
#p bps[n]

bnmax = 0

for j in (0..m)
  bn = psums[j] - bps[n][j]
  bnmax = bn if bnmax < bn
end
p bnmax