from heapq import heappush, heappop from sys import stdin input = stdin.readline inf = 1 << 60 def main(): n, m = map(int, input().split()) edges = [[] for _ in range(n+m)] for i in range(n, n+m): k, c, *s = map(int, input().split()) for j in s: edges[j-1].append((c, i)) edges[i].append(j-1) # Dijkstra heap = [] heappush(heap, (0, 0, 0)) costs = [(inf,inf)] * (n+m) while heap: cost, rem, i = heappop(heap) if costs[i] < (cost,rem): continue if i < n: for c, j in edges[i]: new_cost = (cost + c + (i+1)//2, i+1 & 1) if new_cost < costs[j]: costs[j] = new_cost heappush(heap, (new_cost[0],new_cost[1],j)) else: for j in edges[i]: new_cost = (cost + (j+rem+2)//2, 0) if new_cost < costs[j]: costs[j] = new_cost heappush(heap, (new_cost[0],new_cost[1],j)) if costs[n-1] == (inf, inf): print(-1) else: print(costs[n-1][0]) main()