#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, w, start = 0, k;
long long int MAX = 1e18;
vector<set<int> > wait(100005);
vector<vector<pair<int, int> > > adj(100005);
int main(void) {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i <= m - 1; ++i) {
    cin >> a >> b >> w;
    --a;
    --b;
    adj[a].push_back({b, w});
    adj[b].push_back({a, w});
  }
  for (int i = 0; i <= n - 1; ++i) {
    cin >> k;
    for (int j = 0; j <= k - 1; ++j) {
      cin >> w;
      wait[i].insert(w);
    }
  }
  set<pair<long long int, int> > s;
  vector<long long int> dist(n, MAX);
  vector<int> present(n, 1);
  dist[start] = 0;
  s.insert({dist[start], start});
  while (!s.empty()) {
    auto c = *(s.begin());
    s.erase(c);
    int v = c.second;
    present[v] = 0;
    while (v != n - 1 and wait[v].find(dist[v]) != wait[v].end()) {
      ++dist[v];
    }
    for (auto e : adj[v]) {
      int u = e.first;
      w = e.second;
      if (present[u] and dist[u] > dist[v] + 1LL * w) {
        s.erase({dist[u], u});
        dist[u] = dist[v] + 1LL * w;
        s.insert({dist[u], u});
      }
    }
  }
  if (dist[n - 1] == MAX) {
    cout << -1 << endl;
  } else {
    cout << dist[n - 1] << endl;
  }
  return 0;
}
