from collections import defaultdict
import heapq as pq
def addtime(site, time):
ls = no[site]
if k[site] == 0 or ls[0] > time or ls[-1] < time:
return time
l, r = 0, len(ls)-1
while l < r:
mid = l + r >> 1
if ls[mid] < time:
l = mid + 1
else:
r = mid
if ls[l] > time:
return time
while l < len(ls) and ls[l] == time:
time += 1
l += 1
return time
n, m = map(int,input().split())
edge = defaultdict(dict)
k = [0]*(n+1)
no = [ [] ]
for _ in range(m):
a, b, c = map(int,input().split())
edge[a][b] = c
edge[b][a] = c
for idx in range(1, n+1):
ls = list(map(int,input().split()))
k[idx] = ls[0]
no.append(ls[1:])
qu = []
pq.heapify(qu)
pq.heappush(qu, (1, 0))
v = [float('inf')]*(n+1)
while qu:
site, time = pq.heappop(qu)
if time > v[site]: continue
v[site] = time
time_ = addtime(site, time)
for nex in edge[site]:
if edge[site][nex] + time_ < v[nex]:
pq.heappush(qu, (nex, edge[site][nex] + time_))
if v[-1] == float('inf'):
print(-1)
else:
print(v[-1])