#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > g[100005];
int main() {
  long long n, m, a, b, c;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c;
    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }
  set<int> ss[100005];
  for (int i = 1; i < n + 1; i++) {
    int pn;
    cin >> pn;
    int tmp;
    for (int j = 0; j < pn; j++) {
      cin >> tmp;
      ss[i].insert(tmp);
    }
  }
  int dis[100005];
  priority_queue<pair<int, int> > pq;
  for (int i = 1; i < n + 2; i++) dis[i] = (1 << 30);
  pq.push(make_pair(1, 0));
  dis[1] = 0;
  while (!pq.empty()) {
    int nn = pq.top().first;
    int nt = -pq.top().second;
    pq.pop();
    if (nt != dis[nn]) continue;
    while (ss[nn].count(nt)) nt++;
    for (typeof((g[nn]).begin()) it = (g[nn]).begin(); it != (g[nn]).end();
         it++)
      if (it->second + nt < dis[it->first]) {
        dis[it->first] = it->second + nt;
        pq.push(make_pair(it->first, -(dis[it->first])));
      }
  }
  if (dis[n] >= (1 << 30))
    cout << "-1" << endl;
  else
    cout << dis[n] << endl;
  return 0;
}
