#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > neigh[100005];
vector<int> t[100005];
int dist[100005];
int getTim(int v, int d) {
  for (int i = 0; i < t[v].size(); i++)
    if (d < t[v][i])
      return d;
    else if (d == t[v][i])
      d++;
  return d;
}
int main() {
  cin >> n >> m;
  while (m--) {
    int a, b, c;
    cin >> a >> b >> c;
    neigh[a].push_back(make_pair(b, c));
    neigh[b].push_back(make_pair(a, c));
  }
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    t[i].resize(k);
    for (int j = 0; j < k; j++) cin >> t[i][j];
  }
  fill(dist, dist + 100005, 2e9);
  dist[1] = 0;
  priority_queue<pair<int, int> > q;
  q.push(make_pair(-dist[1], 1));
  while (!q.empty()) {
    int v = q.top().second, d = -q.top().first;
    q.pop();
    if (dist[v] != d) continue;
    if (v == n) break;
    d = getTim(v, d);
    for (int i = 0; i < neigh[v].size(); i++) {
      pair<int, int> u = neigh[v][i];
      if (d + u.second < dist[u.first]) {
        dist[u.first] = d + u.second;
        q.push(make_pair(-dist[u.first], u.first));
      }
    }
  }
  if (dist[n] == 2e9)
    cout << "-1";
  else
    cout << dist[n];
  return 0;
}
