#include <bits/stdc++.h>
using namespace std;
int n, m, s, d;
vector<pair<int, int>> v[100005];
set<int> traveller[100005];
int times[100005];
void dijkstra(int s) {
  set<pair<int, int>> pq;
  times[s] = 0;
  pq.insert({0, s});
  while (!pq.empty()) {
    int x = pq.begin()->second;
    int t = pq.begin()->first;
    pq.erase(pq.begin());
    while (traveller[x].count(t)) t++;
    for (int i = 0; i < v[x].size(); i++) {
      pair<int, int> p = v[x][i];
      int y = p.first;
      int t1 = p.second;
      if (times[y] > t + t1) {
        times[y] = t + t1;
        pq.insert({times[y], y});
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    v[a].push_back({b, c});
    v[b].push_back({a, c});
  }
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    for (int j = 0; j < x; j++) {
      int y;
      cin >> y;
      traveller[i].insert(y);
    }
  }
  s = 0;
  d = n - 1;
  for (int i = 0; i <= 100000; i++) times[i] = 2000000000;
  dijkstra(0);
  if (times[n - 1] != 2000000000)
    cout << times[n - 1];
  else
    cout << -1;
  return 0;
}
