#include <bits/stdc++.h>
using namespace std;
long long int n, m, u, v, t, w, k, d[100005];
vector<pair<long long int, long long int> > v1[100005];
set<long long int> c[100005];
set<pair<long long int, long long int> > q;
int main() {
  cin >> n >> m;
  for (long long int i = 0; i < m; i++) {
    cin >> u >> v >> t;
    u--;
    v--;
    v1[u].push_back({v, t});
    v1[v].push_back({u, t});
  }
  for (long long int i = 0; i < n; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> u;
      c[i].insert(u);
    }
    d[i] = 1e18;
  }
  d[0] = 0;
  q.insert({d[0], 0});
  while (!q.empty()) {
    auto bb = q.begin();
    u = bb->second;
    q.erase(bb);
    w = d[u];
    while (c[u].count(w)) w++;
    for (auto p : v1[u]) {
      v = p.first;
      t = p.second;
      if (t + w < d[v]) {
        q.erase({d[v], v});
        d[v] = t + w;
        q.insert({d[v], v});
      }
    }
  }
  cout << (d[n - 1] == 1e18 ? -1 : d[n - 1]) << endl;
}
