Buggy python submission (verdict: Time Limit Exceeded):
# M: 鍵の数
# N: 宝箱の数(制限値になる)
# openable: 開けられる宝箱のリスト
# price: 鍵の価格

def power(n):
    if n == 0:
        return [[]]
    else:
        l = []
        for i in power(n-1):
            k = i + [n]
            l.append(k)
        return power(n-1) + l

def abc142e(M, N, price, openable):
    # dp initialize
    inf = float("inf")
    dp = [[inf for j in range((2**N)+1)] for i in range(M+10)]
    for i in range(M+10):
        dp[i][0] = 0
    closed_boxes = power(N)
    # dp
    for i in range(M):
        if openable[i] not in closed_boxes:
            dp[i][j] = inf
        else:
            for j in range(len(closed_boxes)):
                l = list(set(closed_boxes[j])-set(openable[i]))
                l.sort()
                dp[i+1][j] = min(dp[i][closed_boxes.index(l)]+price[i], dp[i][j])
    if dp[M][2**N-1] == inf: return -1
    else: return dp[M][2**N-1]

if __name__ == "__main__":
    N,M = map(int, input().split())
    price = []
    openable = []
    for i in range(M):
        a,b = map(int, input().split())
        c = [i for i in map(int, input().split())]
        price.append(a)
        openable.append(c)

    print(abc142e(M, N, price, openable))



Fixed submission:
def main():
    N,M = map(int, input().split())
    inf = 10**9
    p = 2**N
    dp = [inf] * p
    dp[0] = 0
    
    for i in range(M):
        a,b = map(int, input().split())
        c = sum([2**(int(j)-1) for j in list(input().split())])
        for k in range(p):
            if dp[k|c] > dp[k] + a:
                dp[k|c] = dp[k] + a
    if dp[-1] == inf:
        print(-1)
    else:
        print(dp[-1])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):

# M: 鍵の数
# N: 宝箱の数(制限値になる)
# openable: 開けられる宝箱のリスト
# price: 鍵の価格

def power(n):
    if n == 0:
        return [[]]
    else:
        l = []
        for i in power(n-1):
            k = i + [n]
            l.append(k)
        return power(n-1) + l

def abc142e(M, N, price, openable):
    # dp initialize
    inf = float("inf")
    dp = [[inf for j in range((2**N)+1)] for i in range(M+10)]
    for i in range(M+10):
        dp[i][0] = 0
    closed_boxes = power(N)
    # dp
    for i in range(M):
        if openable[i] not in closed_boxes:
            dp[i][j] = inf
        else:
            for j in range(len(closed_boxes)):
                l = list(set(closed_boxes[j])-set(openable[i]))
                l.sort()
                dp[i+1][j] = min(dp[i][closed_boxes.index(l)]+price[i], dp[i][j])
    if dp[M][2**N-1] == inf: return -1
    else: return dp[M][2**N-1]

if __name__ == "__main__":
    N,M = map(int, input().split())
    price = []
    openable = []
    for i in range(M):
        a,b = map(int, input().split())
        c = [i for i in map(int, input().split())]
        price.append(a)
        openable.append(c)

    print(abc142e(M, N, price, openable))



Fixed submission:
def main():
    N,M = map(int, input().split())
    inf = 10**9
    p = 2**N
    dp = [inf] * p
    dp[0] = 0
    
    for i in range(M):
        a,b = map(int, input().split())
        c = sum([2**(int(j)-1) for j in list(input().split())])
        for k in range(p):
            if dp[k|c] > dp[k] + a:
                dp[k|c] = dp[k] + a
    if dp[-1] == inf:
        print(-1)
    else:
        print(dp[-1])

if __name__ == "__main__":
    main()