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|
  all += a[i]
end

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

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

puts ans
