mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline import heapq def dijkstra(adj, start): # adj: [[to, cost] * vertices], 0th index must be empty inf = 1 << 60 dist = [inf] * len(adj) dist[start] = 0 q = [] heapq.heappush(q, (0, start)) while q: min_dist, v_from = heapq.heappop(q) if min_dist > dist[v_from]: continue v_tos = adj[v_from] for v_to, cost in v_tos: if min_dist + cost < dist[v_to]: dist[v_to] = min_dist + cost heapq.heappush(q, (dist[v_to], v_to)) return dist N, M = map(int, input().split()) adj = [[] for _ in range(N+1 + M * 2)] for m in range(1, M+1): KCS = list(map(int, input().split())) k, c = KCS[:2] for s in KCS[2:]: adj[s].append((N + m, (s + 1) // 2)) adj[N + m].append((s, (s + 1) // 2 + c)) if s & 1: adj[s].append((N + m + M, s // 2)) adj[N + m + M].append((s, (s + 1) // 2 + c)) ans = dijkstra(adj, 1)[N] if ans < 1 << 60: print(ans) else: print(-1) if __name__ == '__main__': main()