#include <bits/stdc++.h>   using namespace std;   int n, m;   long long dis[100010];   vector<int> mom[100010];   vector<pair<int, int> > vertex[100010];   set<int> q;   void readin() {     scanf( %d%d , &n, &m);     int u, v, c;     for (int i = 0; i < m; ++i) {       scanf( %d%d%d , &u, &v, &c);       vertex[u].push_back(make_pair(v, c));       vertex[v].push_back(make_pair(u, c));     }     int cnt;     for (int i = 1; i <= n; ++i) {       scanf( %d , &cnt);       while (cnt--) {         scanf( %d , &v);         mom[i].push_back(v);       }     }   }   void spfa() {     int u, v, c, nt, sz;     vector<int>::iterator low;     memset(dis, -1, sizeof(dis));     while (!q.empty()) q.clear();     q.insert(1);     dis[1] = 0;     while (!q.empty()) {       u = *q.begin();       q.erase(u);       if (u == n) continue;       nt = dis[u];       low = lower_bound(mom[u].begin(), mom[u].end(), nt);       for (; low != mom[u].end(); low++) {         if (*low == nt)           nt++;         else if (*low > nt)           break;       }       sz = vertex[u].size();       for (int i = 0; i < sz; ++i) {         v = vertex[u][i].first;         c = vertex[u][i].second;         if (dis[v] == -1 || dis[v] > nt + c) {           dis[v] = nt + c;           q.insert(v);         }       }     }   }   int main() {     readin();     spfa();     printf( %I64d , dis[n]);   }   