#include <bits/stdc++.h>
using namespace std;
long long int V, m;
vector<pair<long long int, long long int>> adj[100000];
set<long long int> ma[100000];
long long int d[100000];
long long int p[100000];
void dijkstra(long long int second) {
  long long int n = V;
  fill(d, d + n, 1000000000000000001);
  fill(p, p + n, -1);
  d[second] = 0;
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      q;
  q.push({0, second});
  while (!q.empty()) {
    long long int v = q.top().second;
    long long int d_v = q.top().first;
    q.pop();
    if (d_v != d[v]) continue;
    long long int dist = d[v];
    while (ma[v].find(dist) != ma[v].end()) dist++;
    for (auto edge : adj[v]) {
      long long int to = edge.first;
      long long int len = edge.second;
      if (dist + len < d[to]) {
        d[to] = dist + len;
        p[to] = v;
        q.push({d[to], to});
      }
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> V >> m;
  for (long long int i = 0; i < m; i++) {
    long long int a, b, c;
    cin >> a >> b >> c;
    adj[a - 1].push_back(make_pair(b - 1, c));
    adj[b - 1].push_back(make_pair(a - 1, c));
  }
  for (long long int i = 0; i < V; i++) {
    long long int k;
    cin >> k;
    long long int prev;
    long long int current;
    for (long long int j = 0; j < k; j++) {
      long long int temp;
      cin >> temp;
      ma[i].insert(temp);
    }
  }
  dijkstra(0);
  if (d[V - 1] == 1000000000000000001)
    cout << -1;
  else
    cout << d[V - 1];
  return 0;
}
