n,m=map(int,input().split())
ab=[]
c=[]
for _ in range(m):
  ab.append(list(map(int,input().split())))
  c.append(list(map(int,input().split())))
dp={'0'*n:0}
for i in range(m):
  a,b=ab[i]
  ci=c[i]
  dptmp={}
  for k,v in dp.items():
    s=list(k)
    for cii in ci:
      s[cii-1]='1'
    t=''.join(s)
    dptmp[t]=min(v+a,dp[t] if t in dp else float('inf'),dptmp[t] if t in dptmp else float('inf'))
  dp.update(dptmp)

t='1'*n
if t in dp:
  print(dp[t])
else:
  print(-1)
#print(dp) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m ab=[] ab [] c=[] c [] for _ in range(m):
  ab.append(list(map(int,input().split())))
  c.append(list(map(int,input().split()))) _ range(m) range m ab.append(list(map(int,input().split()))) ab.append ab append list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split c.append(list(map(int,input().split()))) c.append c append list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split dp={'0'*n:0} dp {'0'*n:0} '0'*n '0'*n '0' n 0 for i in range(m):
  a,b=ab[i]
  ci=c[i]
  dptmp={}
  for k,v in dp.items():
    s=list(k)
    for cii in ci:
      s[cii-1]='1'
    t=''.join(s)
    dptmp[t]=min(v+a,dp[t] if t in dp else float('inf'),dptmp[t] if t in dptmp else float('inf'))
  dp.update(dptmp) i range(m) range m a,b=ab[i] a ab[i] ab i b ci=c[i] ci c[i] c i dptmp={} dptmp {} for k,v in dp.items():
    s=list(k)
    for cii in ci:
      s[cii-1]='1'
    t=''.join(s)
    dptmp[t]=min(v+a,dp[t] if t in dp else float('inf'),dptmp[t] if t in dptmp else float('inf'))
   k v dp.items() dp.items dp items s=list(k) s list(k) list k for cii in ci:
      s[cii-1]='1'
     cii ci s[cii-1]='1' s[cii-1] s cii-1 cii 1 '1' t=''.join(s) t ''.join(s) ''.join '' join s dptmp[t]=min(v+a,dp[t] if t in dp else float('inf'),dptmp[t] if t in dptmp else float('inf')) dptmp[t] dptmp t min(v+a,dp[t] if t in dp else float('inf'),dptmp[t] if t in dptmp else float('inf')) min v+a v a dp[t] if t in dp else float('inf') t in dp t dp dp[t] dp t float('inf') float 'inf' dptmp[t] if t in dptmp else float('inf') t in dptmp t dptmp dptmp[t] dptmp t float('inf') float 'inf' dp.update(dptmp) dp.update dp update dptmp t='1'*n t '1'*n '1' n if t in dp:
  print(dp[t])
else:
  print(-1)
#print(dp) t in dp t dp print(dp[t]) print dp[t] dp t print(-1) print -1 b=ab[i] ab[i] b s=list(k) list(k) s t='1'*n '1'*n t dp={'0'*n:0} {'0'*n:0} dp m=map(int,input().split()) map(int,input().split()) m n,m=map(int,input().split()) map(int,input().split()) n ci=c[i] c[i] ci t=''.join(s) ''.join(s) t c=[] [] c a,b=ab[i] ab[i] a dptmp={} {} dptmp ab=[] [] ab
n,m=map(int,input().split())
ab=[]
c=[]
for _ in range(m):
  ab.append(list(map(int,input().split())))
  c.append(list(map(int,input().split())))
dp={'0'*n:0}
for i in range(m):
  a,b=ab[i]
  ci=c[i]
  dptmp={}
  for k,v in dp.items():
    s=list(k)
    for cii in ci:
      s[cii-1]='1'
    t=''.join(s)
    dptmp[t]=min(v+a,dp[t] if t in dp else float('inf'),dptmp[t] if t in dptmp else float('inf'))
  dp.update(dptmp)

t='1'*n
if t in dp:
  print(dp[t])
else:
  print(-1)
#print(dp)