def main():
    import numpy as np

    n, m = map(int, input().split())
    dp = np.full(2**n, 10**9, dtype=np.int64)
    dp[0] = 0
    opened = np.arange(2**n)

    for _ in range(m):
        cost, types = map(int, input().split())
        to_open = np.array(list(map(int, input().split())), dtype=np.int64)

        openable = np.left_shift(1, to_open-1).sum()
        new_indexes = opened | openable
        new_costs = dp + cost
        sort_index = np.argsort(new_costs)
        new_costs.sort()
        update_pattern, idx = np.unique(new_indexes[sort_index], return_index=True)
        update_cost = new_costs[idx]
        dp[update_pattern] = np.minimum(dp[update_pattern], update_cost)

    full_open = 2**n - 1
    ans = dp[full_open]
    if ans == 10 ** 9:
        ans = -1

    print(ans)


if __name__ == '__main__':
    main() def main():
    import numpy as np

    n, m = map(int, input().split())
    dp = np.full(2**n, 10**9, dtype=np.int64)
    dp[0] = 0
    opened = np.arange(2**n)

    for _ in range(m):
        cost, types = map(int, input().split())
        to_open = np.array(list(map(int, input().split())), dtype=np.int64)

        openable = np.left_shift(1, to_open-1).sum()
        new_indexes = opened | openable
        new_costs = dp + cost
        sort_index = np.argsort(new_costs)
        new_costs.sort()
        update_pattern, idx = np.unique(new_indexes[sort_index], return_index=True)
        update_cost = new_costs[idx]
        dp[update_pattern] = np.minimum(dp[update_pattern], update_cost)

    full_open = 2**n - 1
    ans = dp[full_open]
    if ans == 10 ** 9:
        ans = -1

    print(ans) main import numpy as np numpy n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m dp = np.full(2**n, 10**9, dtype=np.int64) dp np.full(2**n, 10**9, dtype=np.int64) np.full np full 2**n 2 n 10**9 10 9 dtype=np.int64 dtype np.int64 np int64 dp[0] = 0 dp[0] dp 0 0 opened = np.arange(2**n) opened np.arange(2**n) np.arange np arange 2**n 2 n for _ in range(m):
        cost, types = map(int, input().split())
        to_open = np.array(list(map(int, input().split())), dtype=np.int64)

        openable = np.left_shift(1, to_open-1).sum()
        new_indexes = opened | openable
        new_costs = dp + cost
        sort_index = np.argsort(new_costs)
        new_costs.sort()
        update_pattern, idx = np.unique(new_indexes[sort_index], return_index=True)
        update_cost = new_costs[idx]
        dp[update_pattern] = np.minimum(dp[update_pattern], update_cost)

     _ range(m) range m cost, types = map(int, input().split()) cost map(int, input().split()) map int input().split() ().split () input split types to_open = np.array(list(map(int, input().split())), dtype=np.int64) to_open np.array(list(map(int, input().split())), dtype=np.int64) np.array np array list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split dtype=np.int64 dtype np.int64 np int64 openable = np.left_shift(1, to_open-1).sum() openable np.left_shift(1, to_open-1).sum() np.left_shift(1, to_open-1).sum np.left_shift(1, to_open-1) np.left_shift np left_shift 1 to_open-1 to_open 1 sum new_indexes = opened | openable new_indexes opened | openable opened openable new_costs = dp + cost new_costs dp + cost dp cost sort_index = np.argsort(new_costs) sort_index np.argsort(new_costs) np.argsort np argsort new_costs new_costs.sort() new_costs.sort new_costs sort update_pattern, idx = np.unique(new_indexes[sort_index], return_index=True) update_pattern np.unique(new_indexes[sort_index], return_index=True) np.unique np unique new_indexes[sort_index] new_indexes sort_index return_index=True return_index True idx update_cost = new_costs[idx] update_cost new_costs[idx] new_costs idx dp[update_pattern] = np.minimum(dp[update_pattern], update_cost) dp[update_pattern] dp update_pattern np.minimum(dp[update_pattern], update_cost) np.minimum np minimum dp[update_pattern] dp update_pattern update_cost full_open = 2**n - 1 full_open 2**n - 1 2**n 2 n 1 ans = dp[full_open] ans dp[full_open] dp full_open if ans == 10 ** 9:
        ans = -1

     ans == 10 ** 9 ans 10 ** 9 10 9 ans = -1 ans -1 print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    import numpy as np

    n, m = map(int, input().split())
    dp = np.full(2**n, 10**9, dtype=np.int64)
    dp[0] = 0
    opened = np.arange(2**n)

    for _ in range(m):
        cost, types = map(int, input().split())
        to_open = np.array(list(map(int, input().split())), dtype=np.int64)

        openable = np.left_shift(1, to_open-1).sum()
        new_indexes = opened | openable
        new_costs = dp + cost
        sort_index = np.argsort(new_costs)
        new_costs.sort()
        update_pattern, idx = np.unique(new_indexes[sort_index], return_index=True)
        update_cost = new_costs[idx]
        dp[update_pattern] = np.minimum(dp[update_pattern], update_cost)

    full_open = 2**n - 1
    ans = dp[full_open]
    if ans == 10 ** 9:
        ans = -1

    print(ans) def main():
    import numpy as np

    n, m = map(int, input().split())
    dp = np.full(2**n, 10**9, dtype=np.int64)
    dp[0] = 0
    opened = np.arange(2**n)

    for _ in range(m):
        cost, types = map(int, input().split())
        to_open = np.array(list(map(int, input().split())), dtype=np.int64)

        openable = np.left_shift(1, to_open-1).sum()
        new_indexes = opened | openable
        new_costs = dp + cost
        sort_index = np.argsort(new_costs)
        new_costs.sort()
        update_pattern, idx = np.unique(new_indexes[sort_index], return_index=True)
        update_cost = new_costs[idx]
        dp[update_pattern] = np.minimum(dp[update_pattern], update_cost)

    full_open = 2**n - 1
    ans = dp[full_open]
    if ans == 10 ** 9:
        ans = -1

    print(ans) main
def main():
    import numpy as np

    n, m = map(int, input().split())
    dp = np.full(2**n, 10**9, dtype=np.int64)
    dp[0] = 0
    opened = np.arange(2**n)

    for _ in range(m):
        cost, types = map(int, input().split())
        to_open = np.array(list(map(int, input().split())), dtype=np.int64)

        openable = np.left_shift(1, to_open-1).sum()
        new_indexes = opened | openable
        new_costs = dp + cost
        sort_index = np.argsort(new_costs)
        new_costs.sort()
        update_pattern, idx = np.unique(new_indexes[sort_index], return_index=True)
        update_cost = new_costs[idx]
        dp[update_pattern] = np.minimum(dp[update_pattern], update_cost)

    full_open = 2**n - 1
    ans = dp[full_open]
    if ans == 10 ** 9:
        ans = -1

    print(ans)


if __name__ == '__main__':
    main()
