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

a = []
(m+1).times do |i|
  a[i] = gets.split.map(&:to_i)
end

all = []
(m+1).times do |i|
  if i != 0
    a[i][0].times do |e|
      all.push(a[i][1])
    end
  else
    all += a[i]
  end
end

all = all.sort {|a, b| b <=> a }

ans = 0
n.times do |i|
  ans += all[i]
end

puts ans
