N,M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
B,C = readlines.map {|s| s.split.map(&:to_i) }.transpose

M.times do |j|
  A.sort!
  B[j].times {|i| A[i] = C[j] if A[i] < C[j] }
end
puts A.inject(:+)