#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, u, v, d, w;
  cin >> n >> m;
  vector<vector<pair<int, int> > > G(n + 1);
  vector<vector<int> > k(n + 1);
  for (i = 1; i <= m; i++) {
    cin >> u >> v >> d;
    G[u].push_back(make_pair(v, d));
    G[v].push_back(make_pair(u, d));
  }
  for (i = 1; i <= n; i++) {
    cin >> u;
    if (u)
      for (j = 1; j <= u; j++) {
        cin >> v;
        k[i].push_back(v);
      }
  }
  vector<int> D(n + 1, -1);
  vector<int> V(n + 1, 0);
  set<pair<int, int> > s;
  s.insert(make_pair(0, 1));
  D[1] = 0;
  while (!s.empty()) {
    pair<int, int> p = *s.begin();
    s.erase(s.begin());
    u = p.second;
    if (V[u]) continue;
    V[u] = 1;
    if (u != n)
      while (binary_search(k[u].begin(), k[u].end(), D[u])) D[u]++;
    for (vector<pair<int, int> >::iterator c = G[u].begin(); c != G[u].end();
         c++) {
      pair<int, int> p1 = *c;
      v = p1.first;
      w = p1.second;
      if (D[u] + w < D[v] || D[v] == -1) {
        D[v] = D[u] + w;
        s.insert(make_pair(D[v], v));
      }
    }
  }
  cout << D[n];
}
