N,M=gets.split.map(&:to_i)
A=*C=[]
M.times do
  A<<gets.to_i
  C<<gets.split.map(&:to_i).inject(0){|s,i|s+2**(i-1)}
end

dp=Array.new(2**N){10**9}
dp[0]=0
M.times do |i|
  nex=*dp
  (2**N).times do |j|
    k=j|C[i]
    nex[k]=[nex[k],dp[j]+A[i]].min
  end
  dp=nex
end
p dp[2**N-1]==10**9 ? -1 : dp[2**N-1]
