from sys import stdin

n,m = map(int,stdin.readline().rstrip().split())
c = []
a_list = []

def main():
    for i in range(m):
        a,b = map(int,stdin.readline().rstrip().split())
        a_list.append(a)
        c.append(sum(1 << j-1 for j in list(map(int,stdin.readline().rstrip().split()))))

    inf = 10**10
    dp = [inf]*(1 << n)
    dp[0] = 0

    for i in range(1 << n):
        for A,C in zip(a_list,c):
            dp[C|i] = min(dp[C|i],dp[i]+A)

    if dp[-1] == inf:
        print(-1)
    else:
        print(dp[-1])

if __name__ == "__main__":
    main() from sys import stdin n,m = map(int,stdin.readline().rstrip().split()) n map(int,stdin.readline().rstrip().split()) map int stdin.readline().rstrip().split() stdin.readline().rstrip().split stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip split m c = [] c [] a_list = [] a_list [] def main():
    for i in range(m):
        a,b = map(int,stdin.readline().rstrip().split())
        a_list.append(a)
        c.append(sum(1 << j-1 for j in list(map(int,stdin.readline().rstrip().split()))))

    inf = 10**10
    dp = [inf]*(1 << n)
    dp[0] = 0

    for i in range(1 << n):
        for A,C in zip(a_list,c):
            dp[C|i] = min(dp[C|i],dp[i]+A)

    if dp[-1] == inf:
        print(-1)
    else:
        print(dp[-1]) main for i in range(m):
        a,b = map(int,stdin.readline().rstrip().split())
        a_list.append(a)
        c.append(sum(1 << j-1 for j in list(map(int,stdin.readline().rstrip().split()))))

     i range(m) range m a,b = map(int,stdin.readline().rstrip().split()) a map(int,stdin.readline().rstrip().split()) map int stdin.readline().rstrip().split() stdin.readline().rstrip().split stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip split b a_list.append(a) a_list.append a_list append a c.append(sum(1 << j-1 for j in list(map(int,stdin.readline().rstrip().split())))) c.append c append sum(1 << j-1 for j in list(map(int,stdin.readline().rstrip().split()))) sum 1 << j-1 1 j-1 j 1 inf = 10**10 inf 10**10 10 10 dp = [inf]*(1 << n) dp [inf]*(1 << n) [inf] inf 1 << n 1 n dp[0] = 0 dp[0] dp 0 0 for i in range(1 << n):
        for A,C in zip(a_list,c):
            dp[C|i] = min(dp[C|i],dp[i]+A)

     i range(1 << n) range 1 << n 1 n for A,C in zip(a_list,c):
            dp[C|i] = min(dp[C|i],dp[i]+A)

     A C zip(a_list,c) zip a_list c dp[C|i] = min(dp[C|i],dp[i]+A) dp[C|i] dp C|i C i min(dp[C|i],dp[i]+A) min dp[C|i] dp C|i C i dp[i]+A dp[i] dp i A if dp[-1] == inf:
        print(-1)
    else:
        print(dp[-1]) dp[-1] == inf dp[-1] dp -1 inf print(-1) print -1 print(dp[-1]) print dp[-1] dp -1 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main c = [] [] c def main():
    for i in range(m):
        a,b = map(int,stdin.readline().rstrip().split())
        a_list.append(a)
        c.append(sum(1 << j-1 for j in list(map(int,stdin.readline().rstrip().split()))))

    inf = 10**10
    dp = [inf]*(1 << n)
    dp[0] = 0

    for i in range(1 << n):
        for A,C in zip(a_list,c):
            dp[C|i] = min(dp[C|i],dp[i]+A)

    if dp[-1] == inf:
        print(-1)
    else:
        print(dp[-1]) def main():
    for i in range(m):
        a,b = map(int,stdin.readline().rstrip().split())
        a_list.append(a)
        c.append(sum(1 << j-1 for j in list(map(int,stdin.readline().rstrip().split()))))

    inf = 10**10
    dp = [inf]*(1 << n)
    dp[0] = 0

    for i in range(1 << n):
        for A,C in zip(a_list,c):
            dp[C|i] = min(dp[C|i],dp[i]+A)

    if dp[-1] == inf:
        print(-1)
    else:
        print(dp[-1]) main m = map(int,stdin.readline().rstrip().split()) map(int,stdin.readline().rstrip().split()) m a_list = [] [] a_list n,m = map(int,stdin.readline().rstrip().split()) map(int,stdin.readline().rstrip().split()) n
from sys import stdin

n,m = map(int,stdin.readline().rstrip().split())
c = []
a_list = []

def main():
    for i in range(m):
        a,b = map(int,stdin.readline().rstrip().split())
        a_list.append(a)
        c.append(sum(1 << j-1 for j in list(map(int,stdin.readline().rstrip().split()))))

    inf = 10**10
    dp = [inf]*(1 << n)
    dp[0] = 0

    for i in range(1 << n):
        for A,C in zip(a_list,c):
            dp[C|i] = min(dp[C|i],dp[i]+A)

    if dp[-1] == inf:
        print(-1)
    else:
        print(dp[-1])

if __name__ == "__main__":
    main()