import sys
input = sys.stdin.readline

def main():
  n, m = map(int, input().split())
  U = 2**n
  dp = [ [float("inf")]*(2**n) for _ in range(m) ]
  dp[0][0] = 0
  for i in range(1, m):
    a, b = map(int, input().split())
    k = map(int, input().split())
    c = 0
    for l in k:
      c |= 1<<(l-1)
    for j in range(U):
      dp[i][j] = min(dp[i-1][j&(~c)]+a, dp[i-1][j])

  if dp[m-1][2**n-1] == float("inf"):
    print(-1)
  else:
    print(dp[m-1][2**n-1])
    
if __name__ == "__main__":
  main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def main():
  n, m = map(int, input().split())
  U = 2**n
  dp = [ [float("inf")]*(2**n) for _ in range(m) ]
  dp[0][0] = 0
  for i in range(1, m):
    a, b = map(int, input().split())
    k = map(int, input().split())
    c = 0
    for l in k:
      c |= 1<<(l-1)
    for j in range(U):
      dp[i][j] = min(dp[i-1][j&(~c)]+a, dp[i-1][j])

  if dp[m-1][2**n-1] == float("inf"):
    print(-1)
  else:
    print(dp[m-1][2**n-1])
     main n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m U = 2**n U 2**n 2 n [float("inf")]*(2**n) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) [float("inf")]*(2**n) [float("inf")] float("inf") float "inf" 2**n 2 n dp = [ [float("inf")]*(2**n) for _ in range(m) ] dp [ [float("inf")]*(2**n) for _ in range(m) ] dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 for i in range(1, m):
    a, b = map(int, input().split())
    k = map(int, input().split())
    c = 0
    for l in k:
      c |= 1<<(l-1)
    for j in range(U):
      dp[i][j] = min(dp[i-1][j&(~c)]+a, dp[i-1][j])

   i range(1, m) range 1 m a, b = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b k = map(int, input().split()) k map(int, input().split()) map int input().split() ().split () input split c = 0 c 0 for l in k:
      c |= 1<<(l-1)
     l k c |= 1<<(l-1) c 1<<(l-1) 1 l-1 l 1 for j in range(U):
      dp[i][j] = min(dp[i-1][j&(~c)]+a, dp[i-1][j])

   j range(U) range U dp[i][j] = min(dp[i-1][j&(~c)]+a, dp[i-1][j]) dp[i][j] [i] dp i j min(dp[i-1][j&(~c)]+a, dp[i-1][j]) min dp[i-1][j&(~c)]+a dp[i-1][j&(~c)] [i-1] dp i-1 i 1 j&(~c) j ~c c a dp[i-1][j] [i-1] dp i-1 i 1 j if dp[m-1][2**n-1] == float("inf"):
    print(-1)
  else:
    print(dp[m-1][2**n-1])
     dp[m-1][2**n-1] == float("inf") dp[m-1][2**n-1] [m-1] dp m-1 m 1 2**n-1 2**n 2 n 1 float("inf") float "inf" print(-1) print -1 print(dp[m-1][2**n-1]) print dp[m-1][2**n-1] [m-1] dp m-1 m 1 2**n-1 2**n 2 n 1 if __name__ == "__main__":
  main() __name__ == "__main__" __name__ "__main__" main() main input = sys.stdin.readline sys.stdin.readline input def main():
  n, m = map(int, input().split())
  U = 2**n
  dp = [ [float("inf")]*(2**n) for _ in range(m) ]
  dp[0][0] = 0
  for i in range(1, m):
    a, b = map(int, input().split())
    k = map(int, input().split())
    c = 0
    for l in k:
      c |= 1<<(l-1)
    for j in range(U):
      dp[i][j] = min(dp[i-1][j&(~c)]+a, dp[i-1][j])

  if dp[m-1][2**n-1] == float("inf"):
    print(-1)
  else:
    print(dp[m-1][2**n-1])
     def main():
  n, m = map(int, input().split())
  U = 2**n
  dp = [ [float("inf")]*(2**n) for _ in range(m) ]
  dp[0][0] = 0
  for i in range(1, m):
    a, b = map(int, input().split())
    k = map(int, input().split())
    c = 0
    for l in k:
      c |= 1<<(l-1)
    for j in range(U):
      dp[i][j] = min(dp[i-1][j&(~c)]+a, dp[i-1][j])

  if dp[m-1][2**n-1] == float("inf"):
    print(-1)
  else:
    print(dp[m-1][2**n-1])
     main
import sys
input = sys.stdin.readline

def main():
  n, m = map(int, input().split())
  U = 2**n
  dp = [ [float("inf")]*(2**n) for _ in range(m) ]
  dp[0][0] = 0
  for i in range(1, m):
    a, b = map(int, input().split())
    k = map(int, input().split())
    c = 0
    for l in k:
      c |= 1<<(l-1)
    for j in range(U):
      dp[i][j] = min(dp[i-1][j&(~c)]+a, dp[i-1][j])

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