import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # inf = (1 << 31)-1 # md = 10**9+7 md = 998244353 from heapq import * n, m = LI() gg = [[] for _ in range(n+1)] cc = [] mem = [] for g in range(m): k, c, *ss = LI() cc.append(c) mem.append(ss[::-1]) for s in ss: gg[s].append(g) hp = [] dist = [inf]*(n+1) dist[1] = 0 mns = [inf]*m mnu = [-1]*m fin = [0]*(n+1) fin[1] = 1 for g in gg[1]: mns[g] = 1 mnu[g] = 1 mem[g].pop() v = mem[g][-1] d = (v+2)//2+cc[g] dist[v] = d heappush(hp, (d, v)) def update(g): while mem[g] and fin[mem[g][-1]]: mem[g].pop() if not mem[g]: return u = mnu[g] v = mem[g][-1] nd = dist[u]+(u+v+1)//2+cc[g] if nd < dist[v]: dist[v] = nd heappush(hp, (nd, v)) while hp: d, u = heappop(hp) if u == n: break if d > dist[u]: continue fin[u] = 1 for g in gg[u]: cur = d*2+u if cur < mns[g]: mns[g], mnu[g] = cur, u update(g) # pDB(hp, mem) ans = dist[-1] if ans == inf: ans = -1 print(ans)