Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
dp=[float("inf") for _ in range(2**N)]
dp[0]=0
for _ in range(M):
    a,b=map(int,input().split())
    c=sum([2**(int(i)-1) for i in input().split()])
    for v in range(2**N):
        nv=v|c
        dp[nv]=min(dp[nv],dp[v]+a)
if dp[-1]==float("inf"):
    print(-1)
else:
    print(dp[-1])

Fixed submission:
N,M=map(int,input().split())
dp=[float("inf") for _ in range(2**N)]
dp[0]=0
for _ in range(M):
    a,b=map(int,input().split())
    c=sum([2**(int(i)-1) for i in input().split()])
    for v in range(2**N):
        nv=v|c
        dp[nv]=min(dp[nv],dp[v]+a)
if dp[-1]==float("inf"):
    print(-1)
else:
    print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
inf=10**18
dp=[inf for _ in range(2**N)]
dp[0]=0;AB=[];C=[]
for _ in range(M):
    AB.append(tuple(map(int,input().split())))
    C.append(tuple(map(int,input().split())))
for ab,c in zip(AB,C):
    for v in range(2**N):
        nv=int(v)
        for k in c:
            bi=2**(k-1)
            if (v//bi)%2==0:
                nv+=bi
        dp[nv]=min(dp[nv],dp[v]+ab[0])
if dp[-1]==inf:
    print(-1)
else:
    print(dp[-1])

Fixed submission:
N,M=map(int,input().split())
dp=[float("inf") for _ in range(2**N)]
dp[0]=0
for _ in range(M):
    a,b=map(int,input().split())
    c=sum([2**(int(i)-1) for i in input().split()])
    for v in range(2**N):
        nv=v|c
        dp[nv]=min(dp[nv],dp[v]+a)
if dp[-1]==float("inf"):
    print(-1)
else:
    print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
dp=[float("inf") for _ in range(2**N)]
dp[0]=0
for _ in range(M):
    a,b=map(int,input().split())
    C=list(map(int,input().split()))
    for v in range(2**N):
        nv=int(v)
        for c in C:
            bi=2**(c-1)
            if (v//bi)%2==0:
                nv+=bi
        dp[nv]=min(dp[nv],dp[v]+a)
if dp[-1]==float("inf"):
    print(-1)
else:
    print(dp[-1])

Fixed submission:
N,M=map(int,input().split())
dp=[float("inf") for _ in range(2**N)]
dp[0]=0
for _ in range(M):
    a,b=map(int,input().split())
    c=sum([2**(int(i)-1) for i in input().split()])
    for v in range(2**N):
        nv=v|c
        dp[nv]=min(dp[nv],dp[v]+a)
if dp[-1]==float("inf"):
    print(-1)
else:
    print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import copy
def main():
    N,M=map(int,input().split())
    dp=[float("inf") for _ in range(2**N)]
    dp[0]=0
    for _ in range(M):
        a,b=map(int,input().split())
        C=list(map(int,input().split()))
        for v in range(2**N):
            nv=copy.copy(v)
            for c in C:
                bi=2**(c-1)
                if (v//bi)%2==0:
                    nv+=bi
            dp[nv]=min(dp[nv],dp[v]+a)
    if dp[-1]==float("inf"):
        print(-1)
    else:
        print(dp[-1])
main()

Fixed submission:
N,M=map(int,input().split())
dp=[float("inf") for _ in range(2**N)]
dp[0]=0
for _ in range(M):
    a,b=map(int,input().split())
    c=sum([2**(int(i)-1) for i in input().split()])
    for v in range(2**N):
        nv=v|c
        dp[nv]=min(dp[nv],dp[v]+a)
if dp[-1]==float("inf"):
    print(-1)
else:
    print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import copy
def main():
    N,M=map(int,input().split())
    dp=[float("inf") for _ in range(2**N)]
    dp[0]=0
    for _ in range(M):
        a,b=map(int,input().split())
        C=list(map(int,input().split()))
        for v in range(2**N):
            nv=copy.copy(v)
            for c in C:
                bi=2**(c-1)
                if (v//bi)%2==0:
                    nv+=bi
            dp[nv]=min(dp[nv],dp[v]+a)
    if dp[-1]==float("inf"):
        print(-1)
    else:
        print(dp[-1])
main()

Fixed submission:
N,M=map(int,input().split())
dp=[float("inf") for _ in range(2**N)]
dp[0]=0
for _ in range(M):
    a,b=map(int,input().split())
    c=sum([2**(int(i)-1) for i in input().split()])
    for v in range(2**N):
        nv=v|c
        dp[nv]=min(dp[nv],dp[v]+a)
if dp[-1]==float("inf"):
    print(-1)
else:
    print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import copy
N,M=map(int,input().split())
dp=[float("inf") for _ in range(2**N)]
dp[0]=0
for _ in range(M):
    a,b=map(int,input().split())
    C=list(map(int,input().split()))
    for v in range(2**N):
        nv=copy.copy(v)
        for c in C:
            bi=2**(c-1)
            if (v//bi)%2==0:
                nv+=bi
        dp[nv]=min(dp[nv],dp[v]+a)
if dp[-1]==float("inf"):
    print(-1)
else:
    print(dp[-1])

Fixed submission:
N,M=map(int,input().split())
dp=[float("inf") for _ in range(2**N)]
dp[0]=0
for _ in range(M):
    a,b=map(int,input().split())
    c=sum([2**(int(i)-1) for i in input().split()])
    for v in range(2**N):
        nv=v|c
        dp[nv]=min(dp[nv],dp[v]+a)
if dp[-1]==float("inf"):
    print(-1)
else:
    print(dp[-1])