#include <bits/stdc++.h>
using namespace std;
int const bound = 2e6 + 2, N = 5e5 + 2;
long long OO = 1e18;
int oo = 1e9, mod = oo + 7;
int n, m;
vector<pair<int, int> > adj[N];
vector<int> st[N];
int dist[N];
bool vis[N];
priority_queue<pair<int, int> > q;
int dij() {
  fill(dist, dist + n + 1, 2 * oo);
  q.push({0, 1});
  dist[1] = 0;
  while (!q.empty()) {
    pair<int, int> cur = q.top();
    q.pop();
    if (vis[cur.second]) continue;
    vis[cur.second] = 1;
    int cst = -cur.first, pl = cur.second;
    while (binary_search(st[pl].begin(), st[pl].end(), cst)) cst++;
    for (auto v : adj[pl]) {
      int ne = v.first, necst = cst + v.second;
      if (!vis[ne] && dist[ne] > necst) {
        dist[ne] = necst;
        q.push({-necst, ne});
      }
    }
  }
  if (dist[n] == 2 * oo) dist[n] = -1;
  return dist[n];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int(i) = 0; (i) < (m); (i)++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    adj[a].push_back({b, c});
    adj[b].push_back({a, c});
  }
  for (int(i) = 1; (i) <= (n); (i)++) {
    int k;
    scanf("%d", &k);
    for (int(j) = 0; (j) < (k); (j)++) {
      int t;
      scanf("%d", &t);
      st[i].push_back(t);
    }
  }
  printf("%d", dij());
  return 0;
}
