import math

N, M = map(int, input().split())
dp = [math.inf] * pow(2, N)  # (どの宝箱をあけたかのbit)=>現時点の最小値
dp[0] = 0
for _ in range(M):
    a, b = map(int, input().split())
    c = sum([pow(2, int(i)-1) for i in input().split()])
    for i in range(pow(2, N)):
        dp[i | c] = min(dp[i | c], dp[i] + a)
print(dp[-1] if dp[-1]!=math.inf else -1) import math math N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M dp = [math.inf] * pow(2, N) dp [math.inf] * pow(2, N) [math.inf] math.inf math inf pow(2, N) pow 2 N dp[0] = 0 dp[0] dp 0 0 for _ in range(M):
    a, b = map(int, input().split())
    c = sum([pow(2, int(i)-1) for i in input().split()])
    for i in range(pow(2, N)):
        dp[i | c] = min(dp[i | c], dp[i] + a) _ range(M) range M a, b = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b pow(2, int(i)-1) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() pow(2, int(i)-1) pow 2 int(i)-1 int(i) int i 1 c = sum([pow(2, int(i)-1) for i in input().split()]) c sum([pow(2, int(i)-1) for i in input().split()]) sum [pow(2, int(i)-1) for i in input().split()] for i in range(pow(2, N)):
        dp[i | c] = min(dp[i | c], dp[i] + a) i range(pow(2, N)) range pow(2, N) pow 2 N dp[i | c] = min(dp[i | c], dp[i] + a) dp[i | c] dp i | c i c min(dp[i | c], dp[i] + a) min dp[i | c] dp i | c i c dp[i] + a dp[i] dp i a print(dp[-1] if dp[-1]!=math.inf else -1) print dp[-1] if dp[-1]!=math.inf else -1 dp[-1]!=math.inf dp[-1] dp -1 math.inf math inf dp[-1] dp -1 -1 M = map(int, input().split()) map(int, input().split()) M dp = [math.inf] * pow(2, N) [math.inf] * pow(2, N) dp b = map(int, input().split()) map(int, input().split()) b c = sum([pow(2, int(i)-1) for i in input().split()]) sum([pow(2, int(i)-1) for i in input().split()]) c N, M = map(int, input().split()) map(int, input().split()) N a, b = map(int, input().split()) map(int, input().split()) a
import math

N, M = map(int, input().split())
dp = [math.inf] * pow(2, N)  # (どの宝箱をあけたかのbit)=>現時点の最小値
dp[0] = 0
for _ in range(M):
    a, b = map(int, input().split())
    c = sum([pow(2, int(i)-1) for i in input().split()])
    for i in range(pow(2, N)):
        dp[i | c] = min(dp[i | c], dp[i] + a)
print(dp[-1] if dp[-1]!=math.inf else -1)
