Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
N,M=map(int,input().split())

dp=[[[[[[[[[[[[10**9]*2 for _ in range(2)]for _ in range(2)]for _ in range(2)]for _ in range(2)]for _ in range(2)]for _ in range(2)]for _ in range(2)]for _ in range(2)]for _ in range(2)]for _ in range(2)]for _ in range(2)]

dp[0][0][0][0][0][0][0][0][0][0][0][0]=0

for _ in range(M):
    al,bl=map(int,input().split())
    temp=[0]*12
    cl=list(map(int,input().split()))
    for item in cl:
        temp[item-1]=1
    for a in range(2):
        for b in range(2):
            for c in range(2):
                for d in range(2):
                    for e in range(2):
                        for f in range(2):
                            for g in range(2):
                                for h in range(2):
                                    for i in range(2):
                                        for j in range(2):
                                            for k in range(2):
                                                for l in range(2):
                                                    if dp[a][b][c][d][e][f][g][h][i][j][k][l]!=10**9:
                                                        dp[max(a,temp[0])][max(b,temp[1])][max(c,temp[2])][max(d,temp[3])][max(e,temp[4])][max(f,temp[5])][max(g,temp[6])][max(h,temp[7])][max(i,temp[8])][max(j,temp[9])][max(k,temp[10])][max(l,temp[11])]=min(dp[max(a,temp[0])][max(b,temp[1])][max(c,temp[2])][max(d,temp[3])][max(e,temp[4])][max(f,temp[5])][max(g,temp[6])][max(h,temp[7])][max(i,temp[8])][max(j,temp[9])][max(k,temp[10])][max(l,temp[11])],dp[a][b][c][d][e][f][g][h][i][j][k][l]+al)
                                                        
                            
    #print(temp)

fa=[0]*12
for i in range(N):
    fa[i]=1

#print(fa)
if dp[fa[0]][fa[1]][fa[2]][fa[3]][fa[4]][fa[5]][fa[6]][fa[7]][fa[8]][fa[9]][fa[10]][fa[11]]==10**9:
    print(-1)
else:
    print(dp[fa[0]][fa[1]][fa[2]][fa[3]][fa[4]][fa[5]][fa[6]][fa[7]][fa[8]][fa[9]][fa[10]][fa[11]])




Fixed submission:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
N,M=map(int,input().split())

dp=[10**9]*2**N

dp[0]=0

for _ in range(M):
    a,b=map(int,input().split())
    c=list(map(int,input().split()))
    cl=["0"]*N
    for item in c:
        cl[item-1]="1"
    plus=int(str("".join(cl)),2)
    for i in range(len(dp))[::-1]:
        if dp[i]!=10**9:
            #print(i,i|plus)
            dp[i|plus]=min(dp[i|plus],dp[i]+a)
if dp[-1]!=10**9:
    print(dp[-1])
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
N,M=map(int,input().split())

dp=[[[[[[[[[[[[10**9]*2 for _ in range(2)]for _ in range(2)]for _ in range(2)]for _ in range(2)]for _ in range(2)]for _ in range(2)]for _ in range(2)]for _ in range(2)]for _ in range(2)]for _ in range(2)]for _ in range(2)]

dp[0][0][0][0][0][0][0][0][0][0][0][0]=0

for _ in range(M):
    al,bl=map(int,input().split())
    temp=[0]*12
    cl=list(map(int,input().split()))
    for item in cl:
        temp[item-1]=1
    for a in range(2):
        for b in range(2):
            for c in range(2):
                for d in range(2):
                    for e in range(2):
                        for f in range(2):
                            for g in range(2):
                                for h in range(2):
                                    for i in range(2):
                                        for j in range(2):
                                            for k in range(2):
                                                for l in range(2):
                                                    if dp[a][b][c][d][e][f][g][h][i][j][k][l]!=10**9:
                                                        dp[max(a,temp[0])][max(b,temp[1])][max(c,temp[2])][max(d,temp[3])][max(e,temp[4])][max(f,temp[5])][max(g,temp[6])][max(h,temp[7])][max(i,temp[8])][max(j,temp[9])][max(k,temp[10])][max(l,temp[11])]=min(dp[max(a,temp[0])][max(b,temp[1])][max(c,temp[2])][max(d,temp[3])][max(e,temp[4])][max(f,temp[5])][max(g,temp[6])][max(h,temp[7])][max(i,temp[8])][max(j,temp[9])][max(k,temp[10])][max(l,temp[11])],dp[a][b][c][d][e][f][g][h][i][j][k][l]+al)
                                                        
                            
    #print(temp)

fa=[0]*12
for i in range(N):
    fa[i]=1

#print(fa)
if dp[fa[0]][fa[1]][fa[2]][fa[3]][fa[4]][fa[5]][fa[6]][fa[7]][fa[8]][fa[9]][fa[10]][fa[11]]==10**9:
    print(-1)
else:
    print(dp[fa[0]][fa[1]][fa[2]][fa[3]][fa[4]][fa[5]][fa[6]][fa[7]][fa[8]][fa[9]][fa[10]][fa[11]])




Fixed submission:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
N,M=map(int,input().split())

dp=[10**9]*2**N

dp[0]=0

for _ in range(M):
    a,b=map(int,input().split())
    c=list(map(int,input().split()))
    cl=["0"]*N
    for item in c:
        cl[item-1]="1"
    plus=int(str("".join(cl)),2)
    for i in range(len(dp))[::-1]:
        if dp[i]!=10**9:
            #print(i,i|plus)
            dp[i|plus]=min(dp[i|plus],dp[i]+a)
if dp[-1]!=10**9:
    print(dp[-1])
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())

def saiki(m,box,ans):
    if m==M:
        if sum(box)==len(box):
            return ans
        else:
            return 10**18
    else:
        open=box[:]
        for item in l[m][1]:
            open[item]=1
        return min(saiki(m+1,box,ans),saiki(m+1,open,ans+l[m][0]))


l=[]
for _ in range(M):
    a,b=map(int,input().split())
    temp=list(map(lambda x: int(x)-1,input().split()))
    l.append([a,temp])

ans=saiki(0,[0]*N,0)

print(ans if ans!=10**18 else -1)




Fixed submission:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
N,M=map(int,input().split())

dp=[10**9]*2**N

dp[0]=0

for _ in range(M):
    a,b=map(int,input().split())
    c=list(map(int,input().split()))
    cl=["0"]*N
    for item in c:
        cl[item-1]="1"
    plus=int(str("".join(cl)),2)
    for i in range(len(dp))[::-1]:
        if dp[i]!=10**9:
            #print(i,i|plus)
            dp[i|plus]=min(dp[i|plus],dp[i]+a)
if dp[-1]!=10**9:
    print(dp[-1])
else:
    print(-1)