import sys

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    A = [0] * M
    C = [0] * M
    for i in range(M):
        A[i], _ = map(int, input().split())
        C[i] = sum(2 ** (int(c) - 1) for c in input().split())

    INF = 10 ** 18
    dp = [INF] * (2 ** N)
    dp[0] = 0
    for a, c in zip(A, C):
        for s in range(2 ** N):
            dp[s | c] = min(dp[s | c], dp[s] + a)

    ans = dp[-1] if dp[-1] != INF else -1
    print(ans)


if __name__ == "__main__":
    main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def main():
    N, M = map(int, input().split())
    A = [0] * M
    C = [0] * M
    for i in range(M):
        A[i], _ = map(int, input().split())
        C[i] = sum(2 ** (int(c) - 1) for c in input().split())

    INF = 10 ** 18
    dp = [INF] * (2 ** N)
    dp[0] = 0
    for a, c in zip(A, C):
        for s in range(2 ** N):
            dp[s | c] = min(dp[s | c], dp[s] + a)

    ans = dp[-1] if dp[-1] != INF else -1
    print(ans) 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 for i in range(M):
        A[i], _ = map(int, input().split())
        C[i] = sum(2 ** (int(c) - 1) for c in input().split())

     i range(M) range M A[i], _ = map(int, input().split()) A[i] A i map(int, input().split()) map int input().split() ().split () input split _ C[i] = sum(2 ** (int(c) - 1) for c in input().split()) C[i] C i sum(2 ** (int(c) - 1) for c in input().split()) sum 2 ** (int(c) - 1) 2 int(c) - 1 int(c) int c 1 INF = 10 ** 18 INF 10 ** 18 10 18 dp = [INF] * (2 ** N) dp [INF] * (2 ** N) [INF] INF 2 ** N 2 N dp[0] = 0 dp[0] dp 0 0 for a, c in zip(A, C):
        for s in range(2 ** N):
            dp[s | c] = min(dp[s | c], dp[s] + a)

     a c zip(A, C) zip A C for s in range(2 ** N):
            dp[s | c] = min(dp[s | c], dp[s] + a)

     s range(2 ** N) range 2 ** N 2 N dp[s | c] = min(dp[s | c], dp[s] + a) dp[s | c] dp s | c s c min(dp[s | c], dp[s] + a) min dp[s | c] dp s | c s c dp[s] + a dp[s] dp s a ans = dp[-1] if dp[-1] != INF else -1 ans dp[-1] if dp[-1] != INF else -1 dp[-1] != INF dp[-1] dp -1 INF dp[-1] dp -1 -1 print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    N, M = map(int, input().split())
    A = [0] * M
    C = [0] * M
    for i in range(M):
        A[i], _ = map(int, input().split())
        C[i] = sum(2 ** (int(c) - 1) for c in input().split())

    INF = 10 ** 18
    dp = [INF] * (2 ** N)
    dp[0] = 0
    for a, c in zip(A, C):
        for s in range(2 ** N):
            dp[s | c] = min(dp[s | c], dp[s] + a)

    ans = dp[-1] if dp[-1] != INF else -1
    print(ans) def main():
    N, M = map(int, input().split())
    A = [0] * M
    C = [0] * M
    for i in range(M):
        A[i], _ = map(int, input().split())
        C[i] = sum(2 ** (int(c) - 1) for c in input().split())

    INF = 10 ** 18
    dp = [INF] * (2 ** N)
    dp[0] = 0
    for a, c in zip(A, C):
        for s in range(2 ** N):
            dp[s | c] = min(dp[s | c], dp[s] + a)

    ans = dp[-1] if dp[-1] != INF else -1
    print(ans) main input = sys.stdin.readline sys.stdin.readline input
import sys

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    A = [0] * M
    C = [0] * M
    for i in range(M):
        A[i], _ = map(int, input().split())
        C[i] = sum(2 ** (int(c) - 1) for c in input().split())

    INF = 10 ** 18
    dp = [INF] * (2 ** N)
    dp[0] = 0
    for a, c in zip(A, C):
        for s in range(2 ** N):
            dp[s | c] = min(dp[s | c], dp[s] + a)

    ans = dp[-1] if dp[-1] != INF else -1
    print(ans)


if __name__ == "__main__":
    main()
