#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, z, k, dist[100005];
map<int, bool> str[100005];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    q;
vector<pair<int, int> > f[100005];
void dijkstra() {
  for (int i = 1; i <= n; i++) dist[i] = INT_MAX;
  q.push({0, 1});
  dist[1] = 0;
  while (!q.empty()) {
    pair<int, int> top = q.top();
    int jarak = top.first;
    int titik = top.second;
    q.pop();
    if (jarak > dist[titik]) continue;
    for (int i = 0; i < f[titik].size(); i++) {
      int tujuan = f[titik][i].first;
      int jar = f[titik][i].second;
      int comp = jar + jarak;
      int nambah = 0;
      while (str[titik][jarak]) ++jarak, ++nambah;
      comp += nambah;
      if (comp < dist[tujuan]) {
        dist[tujuan] = comp;
        q.push({dist[tujuan], tujuan});
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> z;
    f[x].push_back({y, z});
    f[y].push_back({x, z});
  }
  for (int i = 1; i <= n; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> x;
      str[i][x] = true;
    }
  }
  dijkstra();
  if (dist[n] == INT_MAX)
    cout << -1 << "\n";
  else
    cout << dist[n] << "\n";
}
