import numpy as np

(n,m),*d = [list(map(int, s.split())) for s in open(0)]



inf = 100000000

dp = np.full([2]*n, inf, dtype=np.int)

dp[tuple([0]*n)] = 0



for i in range(m):

    a = d[2*i][0]

    b = d[2*i][1]

    c = d[2*i+1]

    

    l0 = [slice(None)]*n

    l1 = [slice(1,None)]*n

    for x in c:

        l0[x-1] = slice(None,1)

        l1[x-1] = slice(None)

    dp = np.minimum(np.minimum(dp[tuple(l1)], dp[tuple(l0)]+a), dp)

    

ans = dp[tuple([1]*n)]

if ans == inf:

    print((-1))

else:

    print(ans)

import numpy as np

(n,m),*d = [list(map(int, s.split())) for s in open(0)]



inf = 100000000

dp = np.full([2]*n, inf, dtype=np.int)

dp[tuple([0]*n)] = 0



for i in range(m):

    a = d[2*i][0]

    b = d[2*i][1]

    c = d[2*i+1]

    

    l0 = [slice(None)]*n

    for x in c:

        l0[x-1] = slice(None,1)

    dp = np.minimum(dp, dp[tuple(l0)]+a)

    

ans = dp[tuple([1]*n)]

if ans == inf:

    print((-1))

else:

    print(ans)

import numpy as np

(n, m), *d = [list(map(int, s.split())) for s in open(0)]
inf = 100000000
dp = np.full([2] * n, inf, dtype=np.int)
dp[tuple([0] * n)] = 0
for i in range(m):
    a = d[2 * i][0]
    b = d[2 * i][1]
    c = d[2 * i + 1]
    l0 = [slice(None)] * n
    l1 = [slice(1, None)] * n
    for x in c:
        l0[x - 1] = slice(None, 1)
        l1[x - 1] = slice(None)
    dp = np.minimum(np.minimum(dp[tuple(l1)], dp[tuple(l0)] + a), dp)
ans = dp[tuple([1] * n)]
if ans == inf:
    print((-1))
else:
    print(ans)

import numpy as np

(n, m), *d = [list(map(int, s.split())) for s in open(0)]
inf = 100000000
dp = np.full([2] * n, inf, dtype=np.int)
dp[tuple([0] * n)] = 0
for i in range(m):
    a = d[2 * i][0]
    b = d[2 * i][1]
    c = d[2 * i + 1]
    l0 = [slice(None)] * n
    for x in c:
        l0[x - 1] = slice(None, 1)
    dp = np.minimum(dp, dp[tuple(l0)] + a)
ans = dp[tuple([1] * n)]
if ans == inf:
    print((-1))
else:
    print(ans)

-    l1 = [slice(1, None)] * n -        l1[x - 1] = slice(None) -    dp = np.minimum(np.minimum(dp[tuple(l1)], dp[tuple(l0)] + a), dp) +    dp = np.minimum(dp, dp[tuple(l0)] + a)