Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
dp = [[float('inf')] * 2 ** n for _ in range(m + 1)]
dp[0][0] = 0
for i in range(1, m + 1):
    a, b = map(int, input().split())
    c = [int(i_) for i_ in input().split()]
    temp = 0
    for kk in c:
        temp += 1 << (kk - 1)
    for j in range(2 ** n):
        if j == 0:
            dp[i][temp | j] = a
        else:
            dp[i][temp | j] = min(dp[i - 1][j] + a, dp[i][temp | j])
        if (i > 1):
            dp[i][j] = min(dp[i - 1][j], dp[i][j])

if dp[-1][-1] < float("inf"):
    print(dp[-1][-1])
else:
    print(-1)

Fixed submission:
n, m = map(int, input().split())
dp = [[float('inf')] * 2 ** n for _ in range(m + 1)]
dp[0][0] = 0
for i in range(1, m + 1):
    a, b = map(int, input().split())
    c = [int(i_) for i_ in input().split()]
    temp = 0
    for kk in c:
        temp += 1 << (kk - 1)
    for j in range(2 ** n):
        if j == 0:
            dp[i][temp | j] = a
        else:
            dp[i][temp | j] = min(dp[i - 1][j] + a, dp[i][temp | j])
        if (i > 1):
            dp[i][j] = min(dp[i - 1][j], dp[i][j])

if dp[-1][-1] < float("inf"):
    print(dp[-1][-1])
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, m = map(int, input().split())
    dp = [[float("inf"), set([])]  for _ in range(2 ** m)]
    dp[0][0] = 0
    a_list = []
    c_list = []
    for i in range(m):
        a, b = map(int, input().split())
        a_list.append(a)
        c_list.append([int(i) for i in input().split()])

    for i in range(1, 2 ** m):
        for j in range(m):
            c = c_list[j]
            a = a_list[j]
            if (i & (1 << j) == 1 << j):
                if len(set(c) - dp[i - (1 << j)][1]) > 0:
                    if len(set(c) - dp[i][1]) > 0:
                        dp[i][0] = dp[i - (1 << j)][0] + a
                        dp[i][1] = dp[i - (1 << j)][1] | set(c)
                    else:
                        if dp[i][0] > dp[i - (1 << j)][0] + a:
                            dp[i][0] = dp[i - (1 << j)][0] + a
                        else:
                            continue
                elif len(dp[i - (1 << j)][1]) == n:
                    if len(dp[i][1]) == n:                    
                        dp[i][0] = min(dp[i - (1 << j)][0], dp[i][0])
                    elif len(set(c) | dp[i][1]) == n:
                        dp[i][1] = dp[i - (1 << j)][1] | set(c)
                        dp[i][0] = min(dp[i - (1 << j)][0], dp[i][0] + a)
    if len(dp[-1][1]) == n:
        print(dp[-1][0])
    else:
        print(-1)

main()

Fixed submission:
n, m = map(int, input().split())
dp = [[float('inf')] * 2 ** n for _ in range(m + 1)]
dp[0][0] = 0
for i in range(1, m + 1):
    a, b = map(int, input().split())
    c = [int(i_) for i_ in input().split()]
    temp = 0
    for kk in c:
        temp += 1 << (kk - 1)
    for j in range(2 ** n):
        if j == 0:
            dp[i][temp | j] = a
        else:
            dp[i][temp | j] = min(dp[i - 1][j] + a, dp[i][temp | j])
        if (i > 1):
            dp[i][j] = min(dp[i - 1][j], dp[i][j])

if dp[-1][-1] < float("inf"):
    print(dp[-1][-1])
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, m = map(int, input().split())
    dp = [[float("inf"), set([])]  for _ in range(2 ** m)]
    dp[0][0] = 0
    a_list = []
    c_list = []
    for i in range(m):
        a, b = map(int, input().split())
        a_list.append(a)
        c_list.append([int(i) for i in input().split()])

    for i in range(1, 2 ** m):
        for j in range(m):
            c = c_list[j]
            a = a_list[j]
            if (i & (1 << j) == 1 << j):
                if len(set(c) - dp[i - (1 << j)][1]) > 0:
                    if len(set(c) - dp[i][1]) > 0:
                        dp[i][0] = dp[i - (1 << j)][0] + a
                        dp[i][1] = dp[i - (1 << j)][1] | set(c)
                    else:
                        if dp[i][0] > dp[i - (1 << j)][0] + a:
                            dp[i][0] = dp[i - (1 << j)][0] + a
                        else:
                            continue
                elif len(dp[i - (1 << j)][1]) == n:
                    if len(dp[i][1]) == n:                    
                        dp[i][0] = min(dp[i - (1 << j)][0], dp[i][0])
                    elif len(set(c) | dp[i][1]) == n:
                        dp[i][1] = dp[i - (1 << j)][1] | set(c)
                        dp[i][0] = min(dp[i - (1 << j)][0], dp[i][0] + a)
    if len(dp[-1][1]) == n:
        print(dp[-1][0])
    else:
        print(-1)

main()

Fixed submission:
n, m = map(int, input().split())
dp = [[float('inf')] * 2 ** n for _ in range(m + 1)]
dp[0][0] = 0
for i in range(1, m + 1):
    a, b = map(int, input().split())
    c = [int(i_) for i_ in input().split()]
    temp = 0
    for kk in c:
        temp += 1 << (kk - 1)
    for j in range(2 ** n):
        if j == 0:
            dp[i][temp | j] = a
        else:
            dp[i][temp | j] = min(dp[i - 1][j] + a, dp[i][temp | j])
        if (i > 1):
            dp[i][j] = min(dp[i - 1][j], dp[i][j])

if dp[-1][-1] < float("inf"):
    print(dp[-1][-1])
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
dp = [[float("inf"), set([])]  for _ in range(2 ** m)]
dp[0][0] = 0
a_list = []
c_list = []
for i in range(m):
    a, b = map(int, input().split())
    a_list.append(a)
    c_list.append([int(i) for i in input().split()])

for i in range(1, 2 ** m):
    for j in range(m):
        c = c_list[j]
        a = a_list[j]
        if (i & (1 << j) == 1 << j):
            if len(set(c) - dp[i - (1 << j)][1]) > 0:
                if len(set(c) - dp[i][1]) > 0:
                    dp[i][0] = dp[i - (1 << j)][0] + a
                    dp[i][1] = dp[i - (1 << j)][1] | set(c)
                else:
                    if dp[i][0] > dp[i - (1 << j)][0] + a:
                        dp[i][0] = dp[i - (1 << j)][0] + a
                    else:
                        continue
            elif len(dp[i - (1 << j)][1]) == n:
                if len(dp[i][1]) == n:                    
                    dp[i][0] = min(dp[i - (1 << j)][0], dp[i][0])
                elif len(set(c) | dp[i][1]) == n:
                    dp[i][1] = dp[i - (1 << j)][1] | set(c)
                    dp[i][0] = min(dp[i - (1 << j)][0], dp[i][0] + a)
if len(dp[-1][1]) == n:
    print(dp[-1][0])
else:
    print(-1)

Fixed submission:
n, m = map(int, input().split())
dp = [[float('inf')] * 2 ** n for _ in range(m + 1)]
dp[0][0] = 0
for i in range(1, m + 1):
    a, b = map(int, input().split())
    c = [int(i_) for i_ in input().split()]
    temp = 0
    for kk in c:
        temp += 1 << (kk - 1)
    for j in range(2 ** n):
        if j == 0:
            dp[i][temp | j] = a
        else:
            dp[i][temp | j] = min(dp[i - 1][j] + a, dp[i][temp | j])
        if (i > 1):
            dp[i][j] = min(dp[i - 1][j], dp[i][j])

if dp[-1][-1] < float("inf"):
    print(dp[-1][-1])
else:
    print(-1)