N,M = gets.split.map &:to_i

$all = (1..N).to_a

as = []
cs = []

M.times{
	as << gets.to_i
	cs << gets.split.map(&:to_i)
}

$map = {}

(1..N).each{ |x|
	$map[x] = []
}

class Key
	attr_accessor :list, :cost
end

cs.each_with_index{ |c, i|
	c.each{ |x|
		k = Key.new
		k.list = c
		k.cost = as[i]
		$map[x] << k
	}
}

if $map.values.select{ |x| x.size == 0}.size > 0 then
	puts -1
	exit
end

$min = 9999999999999999

def reduce(r, sum)
	remain = $all - r
	
	if remain.size == 0 then
		if $min > sum then
			$min = sum
		end
	else
		$map[remain[0]].each{ |k|
			reduce(r | k.list, sum + k.cost)
		}
	end
end

reduce([], 0)

puts $min
