def main():
    n, m = map(int, input().split())
    costs = [None]*m
    keys = [None]*m
    pattern = 2**n
    inf = 10**12
    dp = [inf]*pattern
    for i in range(m):
        costs[i] = int(input().split()[0])
        keys[i] = sum([1<<(int(i)-1) for i in input().split()])
    dp[0] = 0
    for i in range(pattern):
        for cost, key in zip(costs, keys):
            pi = i|key
            if dp[pi] > cost + dp[i]:
                dp[pi] = cost + dp[i]
    if dp[pattern-1] == inf:
        print(-1)
    else:
        print(dp[pattern-1])
        

if __name__ == "__main__":
    main() def main():
    n, m = map(int, input().split())
    costs = [None]*m
    keys = [None]*m
    pattern = 2**n
    inf = 10**12
    dp = [inf]*pattern
    for i in range(m):
        costs[i] = int(input().split()[0])
        keys[i] = sum([1<<(int(i)-1) for i in input().split()])
    dp[0] = 0
    for i in range(pattern):
        for cost, key in zip(costs, keys):
            pi = i|key
            if dp[pi] > cost + dp[i]:
                dp[pi] = cost + dp[i]
    if dp[pattern-1] == inf:
        print(-1)
    else:
        print(dp[pattern-1])
         main n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m costs = [None]*m costs [None]*m [None] None m keys = [None]*m keys [None]*m [None] None m pattern = 2**n pattern 2**n 2 n inf = 10**12 inf 10**12 10 12 dp = [inf]*pattern dp [inf]*pattern [inf] inf pattern for i in range(m):
        costs[i] = int(input().split()[0])
        keys[i] = sum([1<<(int(i)-1) for i in input().split()])
     i range(m) range m costs[i] = int(input().split()[0]) costs[i] costs i int(input().split()[0]) int input().split()[0] ().split() ().split () input split 0 1<<(int(i)-1) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() 1<<(int(i)-1) 1 int(i)-1 int(i) int i 1 keys[i] = sum([1<<(int(i)-1) for i in input().split()]) keys[i] keys i sum([1<<(int(i)-1) for i in input().split()]) sum [1<<(int(i)-1) for i in input().split()] dp[0] = 0 dp[0] dp 0 0 for i in range(pattern):
        for cost, key in zip(costs, keys):
            pi = i|key
            if dp[pi] > cost + dp[i]:
                dp[pi] = cost + dp[i]
     i range(pattern) range pattern for cost, key in zip(costs, keys):
            pi = i|key
            if dp[pi] > cost + dp[i]:
                dp[pi] = cost + dp[i]
     cost key zip(costs, keys) zip costs keys pi = i|key pi i|key i key if dp[pi] > cost + dp[i]:
                dp[pi] = cost + dp[i]
     dp[pi] > cost + dp[i] dp[pi] dp pi cost + dp[i] cost dp[i] dp i dp[pi] = cost + dp[i] dp[pi] dp pi cost + dp[i] cost dp[i] dp i if dp[pattern-1] == inf:
        print(-1)
    else:
        print(dp[pattern-1])
         dp[pattern-1] == inf dp[pattern-1] dp pattern-1 pattern 1 inf print(-1) print -1 print(dp[pattern-1]) print dp[pattern-1] dp pattern-1 pattern 1 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    n, m = map(int, input().split())
    costs = [None]*m
    keys = [None]*m
    pattern = 2**n
    inf = 10**12
    dp = [inf]*pattern
    for i in range(m):
        costs[i] = int(input().split()[0])
        keys[i] = sum([1<<(int(i)-1) for i in input().split()])
    dp[0] = 0
    for i in range(pattern):
        for cost, key in zip(costs, keys):
            pi = i|key
            if dp[pi] > cost + dp[i]:
                dp[pi] = cost + dp[i]
    if dp[pattern-1] == inf:
        print(-1)
    else:
        print(dp[pattern-1])
         def main():
    n, m = map(int, input().split())
    costs = [None]*m
    keys = [None]*m
    pattern = 2**n
    inf = 10**12
    dp = [inf]*pattern
    for i in range(m):
        costs[i] = int(input().split()[0])
        keys[i] = sum([1<<(int(i)-1) for i in input().split()])
    dp[0] = 0
    for i in range(pattern):
        for cost, key in zip(costs, keys):
            pi = i|key
            if dp[pi] > cost + dp[i]:
                dp[pi] = cost + dp[i]
    if dp[pattern-1] == inf:
        print(-1)
    else:
        print(dp[pattern-1])
         main
def main():
    n, m = map(int, input().split())
    costs = [None]*m
    keys = [None]*m
    pattern = 2**n
    inf = 10**12
    dp = [inf]*pattern
    for i in range(m):
        costs[i] = int(input().split()[0])
        keys[i] = sum([1<<(int(i)-1) for i in input().split()])
    dp[0] = 0
    for i in range(pattern):
        for cost, key in zip(costs, keys):
            pi = i|key
            if dp[pi] > cost + dp[i]:
                dp[pi] = cost + dp[i]
    if dp[pattern-1] == inf:
        print(-1)
    else:
        print(dp[pattern-1])
        

if __name__ == "__main__":
    main()