#include <bits/stdc++.h>
using namespace std;
const int sz = 1e5 + 111;
int N, M;
vector<pair<int, int> > G[sz], busy[sz];
int departsAt(int tm, int idx) {
  vector<pair<int, int> >& busyTime = busy[idx];
  if (busyTime.empty()) return tm;
  if (tm < busyTime.front().first || tm > busyTime.back().second) return tm;
  int l = 0, r = busyTime.size() - 1;
  while (l < r) {
    int mid = (l + r + 1) / 2;
    if (busyTime[mid].first > tm)
      r = mid - 1;
    else
      l = mid;
  }
  if (busyTime[l].first <= tm && busyTime[l].second >= tm)
    return busyTime[l].second + 1;
  else
    return tm;
}
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    pq;
vector<int> dist(sz, -1);
bool insert(int tm, int planet) {
  int nextTime = departsAt(tm, planet);
  if (dist[planet] < 0 || nextTime < dist[planet]) {
    dist[planet] = nextTime;
    pq.push(make_pair(nextTime, planet));
    return true;
  }
  return false;
}
int main() {
  cin >> N >> M;
  for (int i = 1, lets_stop_here = (int)M; i <= lets_stop_here; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    G[a].push_back(make_pair(b, c));
    G[b].push_back(make_pair(a, c));
  }
  for (int i = 1, lets_stop_here = (int)N; i <= lets_stop_here; i++) {
    int K, l = -1, r = -1;
    cin >> K;
    while (K--) {
      int tmp;
      cin >> tmp;
      if (l < 0)
        l = r = tmp;
      else if (tmp - r == 1)
        r = tmp;
      else {
        busy[i].push_back(make_pair(l, r));
        l = r = tmp;
      }
    }
    if (l >= 0) busy[i].push_back(make_pair(l, r));
  }
  busy[N].clear();
  insert(0, 1);
  while (!pq.empty()) {
    int tm = pq.top().first;
    int u = pq.top().second;
    pq.pop();
    if (u == N) {
      cout << tm << ("\n");
      return 0;
    }
    for (__typeof((G[u]).begin()) it = (G[u]).begin(); it != (G[u]).end(); it++)
      insert(it->second + tm, it->first);
  }
  cout << -1 << ("\n");
  return 0;
}
