import sys
inf = float('inf')

n, m = map(int, sys.stdin.readline().split())
graph = [None] * m
for i in range(m):
  a, b = map(int, sys.stdin.readline().split())
  res = 0
  for c in map(int, sys.stdin.readline().split()):
    res |= 1 << (c - 1)
    graph[i] = (a, res)


def main():
  dp = [[0] * (1 << n) for _ in range(m + 1)]
  for i in range(1, 1 << n):
    dp[0][i] = inf

  for i in range(m):
    for j in range(1 << n):
      dp[i+1][j] = min(dp[i][j ^ (j & graph[i][1])] + graph[i][0], dp[i][j])

  ans = dp[m][(1<<n)-1]
  print(-1 if ans == inf else ans)

if __name__ == '__main__':
  main() import sys sys inf = float('inf') inf float('inf') float 'inf' n, m = map(int, sys.stdin.readline().split()) n map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split m graph = [None] * m graph [None] * m [None] None m for i in range(m):
  a, b = map(int, sys.stdin.readline().split())
  res = 0
  for c in map(int, sys.stdin.readline().split()):
    res |= 1 << (c - 1)
    graph[i] = (a, res) i range(m) range m a, b = map(int, sys.stdin.readline().split()) a map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split b res = 0 res 0 for c in map(int, sys.stdin.readline().split()):
    res |= 1 << (c - 1)
    graph[i] = (a, res) c map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split res |= 1 << (c - 1) res 1 << (c - 1) 1 c - 1 c 1 graph[i] = (a, res) graph[i] graph i (a, res) a res def main():
  dp = [[0] * (1 << n) for _ in range(m + 1)]
  for i in range(1, 1 << n):
    dp[0][i] = inf

  for i in range(m):
    for j in range(1 << n):
      dp[i+1][j] = min(dp[i][j ^ (j & graph[i][1])] + graph[i][0], dp[i][j])

  ans = dp[m][(1<<n)-1]
  print(-1 if ans == inf else ans) main [0] * (1 << n) for _ in range(m + 1) for _ in range(m + 1) _ range(m + 1) range m + 1 m 1 for _ in range(m + 1) [0] * (1 << n) [0] 0 1 << n 1 n dp = [[0] * (1 << n) for _ in range(m + 1)] dp [[0] * (1 << n) for _ in range(m + 1)] for i in range(1, 1 << n):
    dp[0][i] = inf

   i range(1, 1 << n) range 1 1 << n 1 n dp[0][i] = inf dp[0][i] [0] dp 0 i inf for i in range(m):
    for j in range(1 << n):
      dp[i+1][j] = min(dp[i][j ^ (j & graph[i][1])] + graph[i][0], dp[i][j])

   i range(m) range m for j in range(1 << n):
      dp[i+1][j] = min(dp[i][j ^ (j & graph[i][1])] + graph[i][0], dp[i][j])

   j range(1 << n) range 1 << n 1 n dp[i+1][j] = min(dp[i][j ^ (j & graph[i][1])] + graph[i][0], dp[i][j]) dp[i+1][j] [i+1] dp i+1 i 1 j min(dp[i][j ^ (j & graph[i][1])] + graph[i][0], dp[i][j]) min dp[i][j ^ (j & graph[i][1])] + graph[i][0] dp[i][j ^ (j & graph[i][1])] [i] dp i j ^ (j & graph[i][1]) j j & graph[i][1] j graph[i][1] [i] graph i 1 graph[i][0] [i] graph i 0 dp[i][j] [i] dp i j ans = dp[m][(1<<n)-1] ans dp[m][(1<<n)-1] [m] dp m (1<<n)-1 1<<n 1 n 1 print(-1 if ans == inf else ans) print -1 if ans == inf else ans ans == inf ans inf -1 ans if __name__ == '__main__':
  main() __name__ == '__main__' __name__ '__main__' main() main res |= 1 << (c - 1) 1 << (c - 1) res def main():
  dp = [[0] * (1 << n) for _ in range(m + 1)]
  for i in range(1, 1 << n):
    dp[0][i] = inf

  for i in range(m):
    for j in range(1 << n):
      dp[i+1][j] = min(dp[i][j ^ (j & graph[i][1])] + graph[i][0], dp[i][j])

  ans = dp[m][(1<<n)-1]
  print(-1 if ans == inf else ans) def main():
  dp = [[0] * (1 << n) for _ in range(m + 1)]
  for i in range(1, 1 << n):
    dp[0][i] = inf

  for i in range(m):
    for j in range(1 << n):
      dp[i+1][j] = min(dp[i][j ^ (j & graph[i][1])] + graph[i][0], dp[i][j])

  ans = dp[m][(1<<n)-1]
  print(-1 if ans == inf else ans) main n, m = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) n a, b = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) a res = 0 0 res inf = float('inf') float('inf') inf b = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) b graph = [None] * m [None] * m graph m = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) m
import sys
inf = float('inf')

n, m = map(int, sys.stdin.readline().split())
graph = [None] * m
for i in range(m):
  a, b = map(int, sys.stdin.readline().split())
  res = 0
  for c in map(int, sys.stdin.readline().split()):
    res |= 1 << (c - 1)
    graph[i] = (a, res)


def main():
  dp = [[0] * (1 << n) for _ in range(m + 1)]
  for i in range(1, 1 << n):
    dp[0][i] = inf

  for i in range(m):
    for j in range(1 << n):
      dp[i+1][j] = min(dp[i][j ^ (j & graph[i][1])] + graph[i][0], dp[i][j])

  ans = dp[m][(1<<n)-1]
  print(-1 if ans == inf else ans)

if __name__ == '__main__':
  main()