Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys

INF = 1<<32
    
def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]"):
    dp = [[INF] * ((1<<N)+1) for i in range(M+1)]
    # for i in map(bin, c):
    #     print(i)

    dp[0][0] = 0
    for i in range(M):
        for j in range(1<<N):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            dp[i+1][j | c[i]] = min(dp[i+1][j | c[i]], dp[i][j]+a[i])

    # for i in dp:
    #     print(i)
    print(dp[M][(1<<N)-1] if (dp[M][(1<<N)-1]) < INF else -1)


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    N, M = map(int, input().split())
    a = []
    b = []
    c = []
    for i in range(M):
        ax, bx = map(int, input().split())
        cx = map(int, input().split())
        a.append(ax)
        b.append(bx)
        ct = 0
        for j in cx:
            ct |= (1<<(j-1))
        c.append(ct)
    solve(N, M, a, b, c)

    
    

if __name__ == '__main__':
    main()


Fixed submission:
def main():
  N,M=map(int,input().split())
  Inf=10**8
  dp=[Inf]*(2**N)
  dp[0]=0
  for i in range(M):
    a,b=map(int,input().split())
    tmp=list(map(int,input().split()))
    open_tresure=list(1<<j-1 for j in tmp)
   # print(open_tresure)
    op_tr=sum(open_tresure)
    for j in range(2**N):
      key=op_tr | j
      dp[key]=min(dp[key],dp[j]+a)
  if dp[-1]==Inf:
    print(-1)
  else:
    print(dp[-1])

main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys

INF = 1<<32
    
def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]"):
    dp = [[INF] * ((1<<N)+1) for i in range(M+1)]
    # for i in map(bin, c):
    #     print(i)

    dp[0][0] = 0
    for i in range(M):
        for j in range(1<<N):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            dp[i+1][j | c[i]] = min(dp[i+1][j | c[i]], dp[i][j]+a[i])

    # for i in dp:
    #     print(i)
    print(dp[M][(1<<N)-1] if (dp[M][(1<<N)-1]) < INF else -1)


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    N, M = map(int, input().split())
    a = []
    b = []
    c = []
    for i in range(M):
        ax, bx = map(int, input().split())
        cx = map(int, input().split())
        a.append(ax)
        b.append(bx)
        ct = 0
        for j in cx:
            ct |= (1<<(j-1))
        c.append(ct)
    solve(N, M, a, b, c)

    
    

if __name__ == '__main__':
    main()


Fixed submission:
def main():
  N,M=map(int,input().split())
  Inf=10**8
  dp=[Inf]*(2**N)
  dp[0]=0
  for i in range(M):
    a,b=map(int,input().split())
    tmp=list(map(int,input().split()))
    open_tresure=list(1<<j-1 for j in tmp)
   # print(open_tresure)
    op_tr=sum(open_tresure)
    for j in range(2**N):
      key=op_tr | j
      dp[key]=min(dp[key],dp[j]+a)
  if dp[-1]==Inf:
    print(-1)
  else:
    print(dp[-1])

main()