import sys from heapq import heappop, heappush input = sys.stdin.buffer.readline N, M = map(int, input().split()) SIZE = N + 2 * M G = [[] for _ in range(SIZE)] def add_undirected_edge(u, v, c): G[u].append((v, c)) G[v].append((u, c)) INF = 10 ** 18 def dijkstra(N, G, s): dist = [INF] * N que = [(0, s)] dist[s] = 0 while que: c, v = heappop(que) if dist[v] < c: continue for t, cost in G[v]: if dist[v] + cost < dist[t]: dist[t] = dist[v] + cost heappush(que, (dist[t], t)) return dist for m in range(N, SIZE, 2): K, C, *S = map(int, input().split()) add_undirected_edge(m, m + 1, 1) for s in S: t = m + s % 2 add_undirected_edge(s - 1, t, C + s) dist = dijkstra(SIZE, G, 0)[N - 1] print(-1 if dist == INF else dist // 2)