n,m=gets.split.map(&:to_i)
a,b,c=[],[],[]
l = [999999] * n
k = []
m.times do |i|
  a[i], b[i] = gets.split.map(&:to_i)
  c[i]=gets.split.map(&:to_i)
  c[i].each do |cc|
    l[cc-1] = a[i] if l[cc-1] > a[i]
  end
end
if l.include?(999999)
  p -1
  exit
end
#p l
p l.inject(:+)
