MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

def main():
    N,M = map(int,input().split())
    key = []
    for _ in range(M):
        a,b = map(int,input().split())
        c = list(map(int,input().split()))
        can_open = 0
        for i in c:
            can_open ^= 1<<(i - 1)
        key.append((a,can_open))
    
    dp = [[INF] * (1<<N) for _ in range(M + 1)]
    for i in range(M):
        dp[i][0] = 0
    
    for i in range(M):
        price,can_open = key[i]
        for s in range(1,1<<N):
            dp[i + 1][s] = min(dp[i][s],dp[i][(s&can_open)^s] + price)
    print(dp[-1][-1] if dp[-1][-1] != INF else -1)

if __name__ == '__main__':
    main() MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 INF = 10 ** 11 INF 10 ** 11 10 11 import sys sys sys.setrecursionlimit(100000000) sys.setrecursionlimit sys setrecursionlimit 100000000 def main():
    N,M = map(int,input().split())
    key = []
    for _ in range(M):
        a,b = map(int,input().split())
        c = list(map(int,input().split()))
        can_open = 0
        for i in c:
            can_open ^= 1<<(i - 1)
        key.append((a,can_open))
    
    dp = [[INF] * (1<<N) for _ in range(M + 1)]
    for i in range(M):
        dp[i][0] = 0
    
    for i in range(M):
        price,can_open = key[i]
        for s in range(1,1<<N):
            dp[i + 1][s] = min(dp[i][s],dp[i][(s&can_open)^s] + price)
    print(dp[-1][-1] if dp[-1][-1] != INF else -1) main N,M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M key = [] key [] for _ in range(M):
        a,b = map(int,input().split())
        c = list(map(int,input().split()))
        can_open = 0
        for i in c:
            can_open ^= 1<<(i - 1)
        key.append((a,can_open))
    
     _ range(M) range M a,b = map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b c = list(map(int,input().split())) c list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split can_open = 0 can_open 0 for i in c:
            can_open ^= 1<<(i - 1)
         i c can_open ^= 1<<(i - 1) can_open 1<<(i - 1) 1 i - 1 i 1 key.append((a,can_open)) key.append key append (a,can_open) a can_open [INF] * (1<<N) for _ in range(M + 1) for _ in range(M + 1) _ range(M + 1) range M + 1 M 1 for _ in range(M + 1) [INF] * (1<<N) [INF] INF 1<<N 1 N dp = [[INF] * (1<<N) for _ in range(M + 1)] dp [[INF] * (1<<N) for _ in range(M + 1)] for i in range(M):
        dp[i][0] = 0
    
     i range(M) range M dp[i][0] = 0 dp[i][0] [i] dp i 0 0 for i in range(M):
        price,can_open = key[i]
        for s in range(1,1<<N):
            dp[i + 1][s] = min(dp[i][s],dp[i][(s&can_open)^s] + price)
     i range(M) range M price,can_open = key[i] price key[i] key i can_open for s in range(1,1<<N):
            dp[i + 1][s] = min(dp[i][s],dp[i][(s&can_open)^s] + price)
     s range(1,1<<N) range 1 1<<N 1 N dp[i + 1][s] = min(dp[i][s],dp[i][(s&can_open)^s] + price) dp[i + 1][s] [i + 1] dp i + 1 i 1 s min(dp[i][s],dp[i][(s&can_open)^s] + price) min dp[i][s] [i] dp i s dp[i][(s&can_open)^s] + price dp[i][(s&can_open)^s] [i] dp i (s&can_open)^s s&can_open s can_open s price print(dp[-1][-1] if dp[-1][-1] != INF else -1) print dp[-1][-1] if dp[-1][-1] != INF else -1 dp[-1][-1] != INF dp[-1][-1] [-1] dp -1 -1 INF dp[-1][-1] [-1] dp -1 -1 -1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    N,M = map(int,input().split())
    key = []
    for _ in range(M):
        a,b = map(int,input().split())
        c = list(map(int,input().split()))
        can_open = 0
        for i in c:
            can_open ^= 1<<(i - 1)
        key.append((a,can_open))
    
    dp = [[INF] * (1<<N) for _ in range(M + 1)]
    for i in range(M):
        dp[i][0] = 0
    
    for i in range(M):
        price,can_open = key[i]
        for s in range(1,1<<N):
            dp[i + 1][s] = min(dp[i][s],dp[i][(s&can_open)^s] + price)
    print(dp[-1][-1] if dp[-1][-1] != INF else -1) def main():
    N,M = map(int,input().split())
    key = []
    for _ in range(M):
        a,b = map(int,input().split())
        c = list(map(int,input().split()))
        can_open = 0
        for i in c:
            can_open ^= 1<<(i - 1)
        key.append((a,can_open))
    
    dp = [[INF] * (1<<N) for _ in range(M + 1)]
    for i in range(M):
        dp[i][0] = 0
    
    for i in range(M):
        price,can_open = key[i]
        for s in range(1,1<<N):
            dp[i + 1][s] = min(dp[i][s],dp[i][(s&can_open)^s] + price)
    print(dp[-1][-1] if dp[-1][-1] != INF else -1) main INF = 10 ** 11 10 ** 11 INF MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

def main():
    N,M = map(int,input().split())
    key = []
    for _ in range(M):
        a,b = map(int,input().split())
        c = list(map(int,input().split()))
        can_open = 0
        for i in c:
            can_open ^= 1<<(i - 1)
        key.append((a,can_open))
    
    dp = [[INF] * (1<<N) for _ in range(M + 1)]
    for i in range(M):
        dp[i][0] = 0
    
    for i in range(M):
        price,can_open = key[i]
        for s in range(1,1<<N):
            dp[i + 1][s] = min(dp[i][s],dp[i][(s&can_open)^s] + price)
    print(dp[-1][-1] if dp[-1][-1] != INF else -1)

if __name__ == '__main__':
    main()
