#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, f;
  cin >> n;
  cin >> m;
  priority_queue<pair<int, int> > mindist;
  vector<int> dist(n + 1, INT_MAX);
  vector<vector<pair<int, int> > > graph(
      n + 1, vector<pair<int, int> >(0, pair<int, int>()));
  for (int i = 1; i < m + 1; ++i) {
    int u, v, d;
    cin >> u >> v >> d;
    graph[v].push_back(make_pair(u, d));
    graph[u].push_back(make_pair(v, d));
  }
  vector<set<int> > timet(n + 1);
  for (int i = 1; i < n + 1; ++i) {
    int u;
    cin >> u;
    for (int j = 0; j < u; ++j) {
      int time;
      cin >> time;
      timet[i].insert(time);
    }
  }
  dist[1] = 0;
  mindist.push(make_pair(0, 1));
  vector<int> vis(n + 1, 0);
  while (!mindist.empty()) {
    pair<int, int> v = mindist.top();
    mindist.pop();
    if (vis[v.second]) continue;
    int cur = v.second;
    vis[cur] = 1;
    int d = -v.first;
    while (timet[cur].find(d) != timet[cur].end()) d++;
    for (int i = 0; i < graph[cur].size(); ++i) {
      int to = graph[cur][i].first;
      if (dist[to] > d + graph[cur][i].second) {
        dist[to] = d + graph[cur][i].second;
        mindist.push(make_pair(-dist[to], to));
      }
    }
  }
  if (dist[n] == INT_MAX)
    cout << -1;
  else
    cout << dist[n];
  return 0;
}
