import sys
sys.setrecursionlimit(10**9)

INF = 10**20
def main():
    N,M = map(int,input().split())

    key = []
    for i in range(M):
        a,_ = map(int,input().split())

        bit = 0
        for c in set(map(int,input().split())):
            bit += 1<<(c-1)

        key.append((a,bit)) # 値段, 開ける宝箱のbit

    dp = [[INF] * (2**N) for _ in range(M+1)]
    dp[0][0] = 0
    for i in range(M):
        for j in range(2**N):
            cost,bit = key[i]

            dp[i+1][j] = min(dp[i+1][j],dp[i][j])
            dp[i+1][j|bit] = min(dp[i+1][j|bit],dp[i][j] + cost)

    last = dp[-2][-1]
    print(last if 0 < last < INF else -1)



if __name__ == "__main__":
  main() import sys sys sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 INF = 10**20 INF 10**20 10 20 def main():
    N,M = map(int,input().split())

    key = []
    for i in range(M):
        a,_ = map(int,input().split())

        bit = 0
        for c in set(map(int,input().split())):
            bit += 1<<(c-1)

        key.append((a,bit)) # 値段, 開ける宝箱のbit

    dp = [[INF] * (2**N) for _ in range(M+1)]
    dp[0][0] = 0
    for i in range(M):
        for j in range(2**N):
            cost,bit = key[i]

            dp[i+1][j] = min(dp[i+1][j],dp[i][j])
            dp[i+1][j|bit] = min(dp[i+1][j|bit],dp[i][j] + cost)

    last = dp[-2][-1]
    print(last if 0 < last < 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 i in range(M):
        a,_ = map(int,input().split())

        bit = 0
        for c in set(map(int,input().split())):
            bit += 1<<(c-1)

        key.append((a,bit)) # 値段, 開ける宝箱のbit

     i range(M) range M a,_ = map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split _ bit = 0 bit 0 for c in set(map(int,input().split())):
            bit += 1<<(c-1)

         c set(map(int,input().split())) set map(int,input().split()) map int input().split() ().split () input split bit += 1<<(c-1) bit 1<<(c-1) 1 c-1 c 1 key.append((a,bit)) key.append key append (a,bit) a bit [INF] * (2**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] * (2**N) [INF] INF 2**N 2 N dp = [[INF] * (2**N) for _ in range(M+1)] dp [[INF] * (2**N) for _ in range(M+1)] dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 for i in range(M):
        for j in range(2**N):
            cost,bit = key[i]

            dp[i+1][j] = min(dp[i+1][j],dp[i][j])
            dp[i+1][j|bit] = min(dp[i+1][j|bit],dp[i][j] + cost)

     i range(M) range M for j in range(2**N):
            cost,bit = key[i]

            dp[i+1][j] = min(dp[i+1][j],dp[i][j])
            dp[i+1][j|bit] = min(dp[i+1][j|bit],dp[i][j] + cost)

     j range(2**N) range 2**N 2 N cost,bit = key[i] cost key[i] key i bit dp[i+1][j] = min(dp[i+1][j],dp[i][j]) dp[i+1][j] [i+1] dp i+1 i 1 j min(dp[i+1][j],dp[i][j]) min dp[i+1][j] [i+1] dp i+1 i 1 j dp[i][j] [i] dp i j dp[i+1][j|bit] = min(dp[i+1][j|bit],dp[i][j] + cost) dp[i+1][j|bit] [i+1] dp i+1 i 1 j|bit j bit min(dp[i+1][j|bit],dp[i][j] + cost) min dp[i+1][j|bit] [i+1] dp i+1 i 1 j|bit j bit dp[i][j] + cost dp[i][j] [i] dp i j cost last = dp[-2][-1] last dp[-2][-1] [-2] dp -2 -1 print(last if 0 < last < INF else -1) print last if 0 < last < INF else -1 0 < last < INF 0 < last 0 last INF last -1 if __name__ == "__main__":
  main() __name__ == "__main__" __name__ "__main__" main() main INF = 10**20 10**20 INF def main():
    N,M = map(int,input().split())

    key = []
    for i in range(M):
        a,_ = map(int,input().split())

        bit = 0
        for c in set(map(int,input().split())):
            bit += 1<<(c-1)

        key.append((a,bit)) # 値段, 開ける宝箱のbit

    dp = [[INF] * (2**N) for _ in range(M+1)]
    dp[0][0] = 0
    for i in range(M):
        for j in range(2**N):
            cost,bit = key[i]

            dp[i+1][j] = min(dp[i+1][j],dp[i][j])
            dp[i+1][j|bit] = min(dp[i+1][j|bit],dp[i][j] + cost)

    last = dp[-2][-1]
    print(last if 0 < last < INF else -1) def main():
    N,M = map(int,input().split())

    key = []
    for i in range(M):
        a,_ = map(int,input().split())

        bit = 0
        for c in set(map(int,input().split())):
            bit += 1<<(c-1)

        key.append((a,bit)) # 値段, 開ける宝箱のbit

    dp = [[INF] * (2**N) for _ in range(M+1)]
    dp[0][0] = 0
    for i in range(M):
        for j in range(2**N):
            cost,bit = key[i]

            dp[i+1][j] = min(dp[i+1][j],dp[i][j])
            dp[i+1][j|bit] = min(dp[i+1][j|bit],dp[i][j] + cost)

    last = dp[-2][-1]
    print(last if 0 < last < INF else -1) main
import sys
sys.setrecursionlimit(10**9)

INF = 10**20
def main():
    N,M = map(int,input().split())

    key = []
    for i in range(M):
        a,_ = map(int,input().split())

        bit = 0
        for c in set(map(int,input().split())):
            bit += 1<<(c-1)

        key.append((a,bit)) # 値段, 開ける宝箱のbit

    dp = [[INF] * (2**N) for _ in range(M+1)]
    dp[0][0] = 0
    for i in range(M):
        for j in range(2**N):
            cost,bit = key[i]

            dp[i+1][j] = min(dp[i+1][j],dp[i][j])
            dp[i+1][j|bit] = min(dp[i+1][j|bit],dp[i][j] + cost)

    last = dp[-2][-1]
    print(last if 0 < last < INF else -1)



if __name__ == "__main__":
  main()
