#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100, INF = 0x3f3f3f3f;
int n, m;
set<int> t[MAXN];
vector<pair<int, int>> g[MAXN];
int dijkstra() {
  int dist[MAXN], v, aux;
  memset(dist, INF, sizeof dist);
  dist[1] = 0;
  priority_queue<pair<int, int>> q;
  q.push({-dist[1], 1});
  while (!q.empty()) {
    v = q.top().second, q.pop();
    aux = dist[v];
    while (t[v].find(aux) != t[v].end()) aux++;
    for (const auto& [w, u] : g[v])
      if (aux + w <= dist[u]) dist[u] = aux + w, q.push({-dist[u], u});
  }
  return dist[n] == INF ? -1 : dist[n];
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1, a, b, c; i <= m; ++i)
    scanf("%d %d %d", &a, &b, &c), g[a].push_back({c, b}),
        g[b].push_back({c, a});
  for (int i = 1, k, x; i <= n; ++i) {
    scanf("%d", &k);
    for (int j = 1; j <= k; ++j) scanf("%d", &x), t[i].insert(x);
  }
  printf("%d\n", dijkstra());
}
