def main():
    n,m=map(int,input().split())
    a=[0]*m
    c=[0]*m
    INF=10**9
    dp=[INF]*2**n
    for i in range(m):
        a[i]=int(input().split()[0])
        c[i]=sum([1<<(int(i)-1) for i in input().split()])
    dp[0]=0
    for i in range(2**n):
        for cos,pat in zip(a,c):
            npat=i|pat
            if dp[npat]>cos+dp[i]:
                dp[npat]=cos+dp[i]
    if dp[2**n-1]==INF:
        print(-1)
    else:
        print(dp[2**n-1])

if __name__ == '__main__':
    main() def main():
    n,m=map(int,input().split())
    a=[0]*m
    c=[0]*m
    INF=10**9
    dp=[INF]*2**n
    for i in range(m):
        a[i]=int(input().split()[0])
        c[i]=sum([1<<(int(i)-1) for i in input().split()])
    dp[0]=0
    for i in range(2**n):
        for cos,pat in zip(a,c):
            npat=i|pat
            if dp[npat]>cos+dp[i]:
                dp[npat]=cos+dp[i]
    if dp[2**n-1]==INF:
        print(-1)
    else:
        print(dp[2**n-1]) main n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m a=[0]*m a [0]*m [0] 0 m c=[0]*m c [0]*m [0] 0 m INF=10**9 INF 10**9 10 9 dp=[INF]*2**n dp [INF]*2**n [INF] INF 2**n 2 n for i in range(m):
        a[i]=int(input().split()[0])
        c[i]=sum([1<<(int(i)-1) for i in input().split()])
     i range(m) range m a[i]=int(input().split()[0]) a[i] a 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 c[i]=sum([1<<(int(i)-1) for i in input().split()]) c[i] c 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(2**n):
        for cos,pat in zip(a,c):
            npat=i|pat
            if dp[npat]>cos+dp[i]:
                dp[npat]=cos+dp[i]
     i range(2**n) range 2**n 2 n for cos,pat in zip(a,c):
            npat=i|pat
            if dp[npat]>cos+dp[i]:
                dp[npat]=cos+dp[i]
     cos pat zip(a,c) zip a c npat=i|pat npat i|pat i pat if dp[npat]>cos+dp[i]:
                dp[npat]=cos+dp[i]
     dp[npat]>cos+dp[i] dp[npat] dp npat cos+dp[i] cos dp[i] dp i dp[npat]=cos+dp[i] dp[npat] dp npat cos+dp[i] cos dp[i] dp i if dp[2**n-1]==INF:
        print(-1)
    else:
        print(dp[2**n-1]) dp[2**n-1]==INF dp[2**n-1] dp 2**n-1 2**n 2 n 1 INF print(-1) print -1 print(dp[2**n-1]) print dp[2**n-1] dp 2**n-1 2**n 2 n 1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n,m=map(int,input().split())
    a=[0]*m
    c=[0]*m
    INF=10**9
    dp=[INF]*2**n
    for i in range(m):
        a[i]=int(input().split()[0])
        c[i]=sum([1<<(int(i)-1) for i in input().split()])
    dp[0]=0
    for i in range(2**n):
        for cos,pat in zip(a,c):
            npat=i|pat
            if dp[npat]>cos+dp[i]:
                dp[npat]=cos+dp[i]
    if dp[2**n-1]==INF:
        print(-1)
    else:
        print(dp[2**n-1]) def main():
    n,m=map(int,input().split())
    a=[0]*m
    c=[0]*m
    INF=10**9
    dp=[INF]*2**n
    for i in range(m):
        a[i]=int(input().split()[0])
        c[i]=sum([1<<(int(i)-1) for i in input().split()])
    dp[0]=0
    for i in range(2**n):
        for cos,pat in zip(a,c):
            npat=i|pat
            if dp[npat]>cos+dp[i]:
                dp[npat]=cos+dp[i]
    if dp[2**n-1]==INF:
        print(-1)
    else:
        print(dp[2**n-1]) main
def main():
    n,m=map(int,input().split())
    a=[0]*m
    c=[0]*m
    INF=10**9
    dp=[INF]*2**n
    for i in range(m):
        a[i]=int(input().split()[0])
        c[i]=sum([1<<(int(i)-1) for i in input().split()])
    dp[0]=0
    for i in range(2**n):
        for cos,pat in zip(a,c):
            npat=i|pat
            if dp[npat]>cos+dp[i]:
                dp[npat]=cos+dp[i]
    if dp[2**n-1]==INF:
        print(-1)
    else:
        print(dp[2**n-1])

if __name__ == '__main__':
    main()