# 15:20-

n, m = map(int, input().split())

dp = [[float("inf") for _ in range(2 ** n)] for i in range(m + 1)]
dp[0][0] = 0

pattern = {0}

for i in range(1, m+1):
  ai, bi = map(int, input().split()) 
  ci_bit = sum(2 ** (cij - 1) for cij in map(int, input().split()))
  new_pattern = set()
  for j in pattern:
    dp[i][j | ci_bit] = min(dp[i][j | ci_bit], dp[i-1][j] + ai)
    dp[i][j] = min(dp[i][j], dp[i-1][j])
    new_pattern.add(j | ci_bit)
  pattern |= new_pattern


print(-1 if dp[m][2**n - 1] == float("inf") else dp[m][2**n - 1]) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m [float("inf") for _ in range(2 ** n)] for i in range(m + 1) for i in range(m + 1) i range(m + 1) range m + 1 m 1 for i in range(m + 1) [float("inf") for _ in range(2 ** n)] dp = [[float("inf") for _ in range(2 ** n)] for i in range(m + 1)] dp [[float("inf") for _ in range(2 ** n)] for i in range(m + 1)] dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 pattern = {0} pattern {0} for i in range(1, m+1):
  ai, bi = map(int, input().split()) 
  ci_bit = sum(2 ** (cij - 1) for cij in map(int, input().split()))
  new_pattern = set()
  for j in pattern:
    dp[i][j | ci_bit] = min(dp[i][j | ci_bit], dp[i-1][j] + ai)
    dp[i][j] = min(dp[i][j], dp[i-1][j])
    new_pattern.add(j | ci_bit)
  pattern |= new_pattern i range(1, m+1) range 1 m+1 m 1 ai, bi = map(int, input().split()) ai map(int, input().split()) map int input().split() ().split () input split bi ci_bit = sum(2 ** (cij - 1) for cij in map(int, input().split())) ci_bit sum(2 ** (cij - 1) for cij in map(int, input().split())) sum 2 ** (cij - 1) 2 cij - 1 cij 1 new_pattern = set() new_pattern set() set for j in pattern:
    dp[i][j | ci_bit] = min(dp[i][j | ci_bit], dp[i-1][j] + ai)
    dp[i][j] = min(dp[i][j], dp[i-1][j])
    new_pattern.add(j | ci_bit)
   j pattern dp[i][j | ci_bit] = min(dp[i][j | ci_bit], dp[i-1][j] + ai) dp[i][j | ci_bit] [i] dp i j | ci_bit j ci_bit min(dp[i][j | ci_bit], dp[i-1][j] + ai) min dp[i][j | ci_bit] [i] dp i j | ci_bit j ci_bit dp[i-1][j] + ai dp[i-1][j] [i-1] dp i-1 i 1 j ai dp[i][j] = min(dp[i][j], dp[i-1][j]) dp[i][j] [i] dp i j min(dp[i][j], dp[i-1][j]) min dp[i][j] [i] dp i j dp[i-1][j] [i-1] dp i-1 i 1 j new_pattern.add(j | ci_bit) new_pattern.add new_pattern add j | ci_bit j ci_bit pattern |= new_pattern pattern new_pattern print(-1 if dp[m][2**n - 1] == float("inf") else dp[m][2**n - 1]) print -1 if dp[m][2**n - 1] == float("inf") else dp[m][2**n - 1] dp[m][2**n - 1] == float("inf") dp[m][2**n - 1] [m] dp m 2**n - 1 2**n 2 n 1 float("inf") float "inf" -1 dp[m][2**n - 1] [m] dp m 2**n - 1 2**n 2 n 1 new_pattern = set() set() new_pattern dp = [[float("inf") for _ in range(2 ** n)] for i in range(m + 1)] [[float("inf") for _ in range(2 ** n)] for i in range(m + 1)] dp ci_bit = sum(2 ** (cij - 1) for cij in map(int, input().split())) sum(2 ** (cij - 1) for cij in map(int, input().split())) ci_bit pattern |= new_pattern new_pattern pattern m = map(int, input().split()) map(int, input().split()) m ai, bi = map(int, input().split()) map(int, input().split()) ai pattern = {0} {0} pattern n, m = map(int, input().split()) map(int, input().split()) n bi = map(int, input().split()) map(int, input().split()) bi
# 15:20-

n, m = map(int, input().split())

dp = [[float("inf") for _ in range(2 ** n)] for i in range(m + 1)]
dp[0][0] = 0

pattern = {0}

for i in range(1, m+1):
  ai, bi = map(int, input().split()) 
  ci_bit = sum(2 ** (cij - 1) for cij in map(int, input().split()))
  new_pattern = set()
  for j in pattern:
    dp[i][j | ci_bit] = min(dp[i][j | ci_bit], dp[i-1][j] + ai)
    dp[i][j] = min(dp[i][j], dp[i-1][j])
    new_pattern.add(j | ci_bit)
  pattern |= new_pattern


print(-1 if dp[m][2**n - 1] == float("inf") else dp[m][2**n - 1])