#include <bits/stdc++.h>   using namespace std;   const long long OO = (long long)1e15;   const double EPS = 1e-11;   vector<vector<pair<long long, int> > > adj;   vector<vector<long long> > ar;   vector<vector<long long> > dep;   long long nxt(int node, long long time) {     int idx =         lower_bound(ar[node].begin(), ar[node].end(), time) - ar[node].begin();     if (idx >= (int)ar[node].size() || ar[node][idx] != time) return 0;     return dep[node][idx] - time;   }   long long dij(int src, int d, int len) {     priority_queue<pair<long long, int>, vector<pair<long long, int> >,                    greater<pair<long long, int> > >         q;     long long cst = nxt(src, 0);     q.push(make_pair((cst), (src)));     vector<long long> dest(len, OO);     dest[src] = q.top().first;     while (!q.empty()) {       int n = q.top().second;       long long c = q.top().first;       q.pop();       if (c != dest[n]) continue;       if (n == d) return c;       for (int i = 0; i < (int)adj[n].size(); ++i) {         int tn = adj[n][i].second;         long long tc = adj[n][i].first;         long long nc = c + tc + ((tn == d) ? 0 : nxt(tn, c + tc));         if (nc < dest[tn]) {           dest[tn] = nc;           q.push(make_pair((dest[tn]), (tn)));         }       }     }     return -1;   }   int main() {     int n, m, a, b, k;     cin >> n >> m;     adj.clear();     adj.resize(n);     long long c;     for (int i = 0; i < m; ++i) {       cin >> a >> b >> c;       a--, b--;       adj[a].push_back(make_pair((c), (b)));       swap(a, b);       adj[a].push_back(make_pair((c), (b)));     }     ar.clear();     dep.clear();     ar.resize(n);     dep.resize(n);     for (int i = 0; i < n; ++i) {       cin >> k;       if (k == 0) continue;       ar[i].resize(k);       dep[i].resize(k);       for (int j = 0; j < k; ++j) {         cin >> ar[i][j];       }       dep[i][k - 1] = ar[i][k - 1] + 1;       for (int j = k - 2; j >= 0; --j) {         if (ar[i][j] + 1 != ar[i][j + 1])           dep[i][j] = ar[i][j] + 1;         else           dep[i][j] = dep[i][j + 1];       }     }     cout << dij(0, n - 1, n) << endl;     return 0;   }   