import sys
def main():
    input = sys.stdin.readline
    N,M=map(int, input().split())
    A,B,C=[],[],[]
    for _ in range(M):
        a,b=map(int, input().split())
        A.append(a)
        B.append(b-1)
        C.append(list(map(lambda x:int(x)-1, input().split())))

    #dp[i][j]=i番目の鍵まで見たとき、jの宝箱を開けられるようになった場合の費用の最小値
    dp = [[10**9] * (1<<N) for _ in range(M+1)]
    dp[0][0] = 0

    for i in range(M):
        ni = i + 1
        nj = 0
        for c in C[i]: nj |= 1 << c
        for j in range(1<<N):
            dp[ni][j] = min(dp[ni][j], dp[i][j])
            dp[ni][j|nj] = min(dp[ni][j|nj], dp[i][j] + A[i])

    print(dp[M][(1<<N)-1] if dp[M][(1<<N)-1] < 10**9 else -1)

if __name__ == '__main__':
    main() import sys sys def main():
    input = sys.stdin.readline
    N,M=map(int, input().split())
    A,B,C=[],[],[]
    for _ in range(M):
        a,b=map(int, input().split())
        A.append(a)
        B.append(b-1)
        C.append(list(map(lambda x:int(x)-1, input().split())))

    #dp[i][j]=i番目の鍵まで見たとき、jの宝箱を開けられるようになった場合の費用の最小値
    dp = [[10**9] * (1<<N) for _ in range(M+1)]
    dp[0][0] = 0

    for i in range(M):
        ni = i + 1
        nj = 0
        for c in C[i]: nj |= 1 << c
        for j in range(1<<N):
            dp[ni][j] = min(dp[ni][j], dp[i][j])
            dp[ni][j|nj] = min(dp[ni][j|nj], dp[i][j] + A[i])

    print(dp[M][(1<<N)-1] if dp[M][(1<<N)-1] < 10**9 else -1) main input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N,M=map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A,B,C=[],[],[] A [] B [] C [] for _ in range(M):
        a,b=map(int, input().split())
        A.append(a)
        B.append(b-1)
        C.append(list(map(lambda x:int(x)-1, input().split())))

    #dp[i][j]=i番目の鍵まで見たとき、jの宝箱を開けられるようになった場合の費用の最小値
     _ range(M) range M a,b=map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b A.append(a) A.append A append a B.append(b-1) B.append B append b-1 b 1 C.append(list(map(lambda x:int(x)-1, input().split()))) C.append C append list(map(lambda x:int(x)-1, input().split())) list map(lambda x:int(x)-1, input().split()) map lambda x:int(x)-1 int(x)-1 int(x) int x 1 x input().split() ().split () input split [10**9] * (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) [10**9] * (1<<N) [10**9] 10**9 10 9 1<<N 1 N dp = [[10**9] * (1<<N) for _ in range(M+1)] dp [[10**9] * (1<<N) for _ in range(M+1)] dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 for i in range(M):
        ni = i + 1
        nj = 0
        for c in C[i]: nj |= 1 << c
        for j in range(1<<N):
            dp[ni][j] = min(dp[ni][j], dp[i][j])
            dp[ni][j|nj] = min(dp[ni][j|nj], dp[i][j] + A[i])

     i range(M) range M ni = i + 1 ni i + 1 i 1 nj = 0 nj 0 for c in C[i]: nj |= 1 << c
         c C[i] C i for j in range(1<<N):
            dp[ni][j] = min(dp[ni][j], dp[i][j])
            dp[ni][j|nj] = min(dp[ni][j|nj], dp[i][j] + A[i])

     j range(1<<N) range 1<<N 1 N dp[ni][j] = min(dp[ni][j], dp[i][j]) dp[ni][j] [ni] dp ni j min(dp[ni][j], dp[i][j]) min dp[ni][j] [ni] dp ni j dp[i][j] [i] dp i j dp[ni][j|nj] = min(dp[ni][j|nj], dp[i][j] + A[i]) dp[ni][j|nj] [ni] dp ni j|nj j nj min(dp[ni][j|nj], dp[i][j] + A[i]) min dp[ni][j|nj] [ni] dp ni j|nj j nj dp[i][j] + A[i] dp[i][j] [i] dp i j A[i] A i print(dp[M][(1<<N)-1] if dp[M][(1<<N)-1] < 10**9 else -1) print dp[M][(1<<N)-1] if dp[M][(1<<N)-1] < 10**9 else -1 dp[M][(1<<N)-1] < 10**9 dp[M][(1<<N)-1] [M] dp M (1<<N)-1 1<<N 1 N 1 10**9 10 9 dp[M][(1<<N)-1] [M] dp M (1<<N)-1 1<<N 1 N 1 -1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    input = sys.stdin.readline
    N,M=map(int, input().split())
    A,B,C=[],[],[]
    for _ in range(M):
        a,b=map(int, input().split())
        A.append(a)
        B.append(b-1)
        C.append(list(map(lambda x:int(x)-1, input().split())))

    #dp[i][j]=i番目の鍵まで見たとき、jの宝箱を開けられるようになった場合の費用の最小値
    dp = [[10**9] * (1<<N) for _ in range(M+1)]
    dp[0][0] = 0

    for i in range(M):
        ni = i + 1
        nj = 0
        for c in C[i]: nj |= 1 << c
        for j in range(1<<N):
            dp[ni][j] = min(dp[ni][j], dp[i][j])
            dp[ni][j|nj] = min(dp[ni][j|nj], dp[i][j] + A[i])

    print(dp[M][(1<<N)-1] if dp[M][(1<<N)-1] < 10**9 else -1) def main():
    input = sys.stdin.readline
    N,M=map(int, input().split())
    A,B,C=[],[],[]
    for _ in range(M):
        a,b=map(int, input().split())
        A.append(a)
        B.append(b-1)
        C.append(list(map(lambda x:int(x)-1, input().split())))

    #dp[i][j]=i番目の鍵まで見たとき、jの宝箱を開けられるようになった場合の費用の最小値
    dp = [[10**9] * (1<<N) for _ in range(M+1)]
    dp[0][0] = 0

    for i in range(M):
        ni = i + 1
        nj = 0
        for c in C[i]: nj |= 1 << c
        for j in range(1<<N):
            dp[ni][j] = min(dp[ni][j], dp[i][j])
            dp[ni][j|nj] = min(dp[ni][j|nj], dp[i][j] + A[i])

    print(dp[M][(1<<N)-1] if dp[M][(1<<N)-1] < 10**9 else -1) main
import sys
def main():
    input = sys.stdin.readline
    N,M=map(int, input().split())
    A,B,C=[],[],[]
    for _ in range(M):
        a,b=map(int, input().split())
        A.append(a)
        B.append(b-1)
        C.append(list(map(lambda x:int(x)-1, input().split())))

    #dp[i][j]=i番目の鍵まで見たとき、jの宝箱を開けられるようになった場合の費用の最小値
    dp = [[10**9] * (1<<N) for _ in range(M+1)]
    dp[0][0] = 0

    for i in range(M):
        ni = i + 1
        nj = 0
        for c in C[i]: nj |= 1 << c
        for j in range(1<<N):
            dp[ni][j] = min(dp[ni][j], dp[i][j])
            dp[ni][j|nj] = min(dp[ni][j|nj], dp[i][j] + A[i])

    print(dp[M][(1<<N)-1] if dp[M][(1<<N)-1] < 10**9 else -1)

if __name__ == '__main__':
    main()