#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int k, l;
  Edge() {}
  Edge(int _k, int _l) : k(_k), l(_l) {}
};
vector<Edge> e[100100];
priority_queue<pair<int, int> > q;
set<int> s[100100];
int dist[100100];
int main() {
  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b, c;
    cin >> a >> b >> c;
    e[a].push_back(Edge(b, c));
    e[b].push_back(Edge(a, c));
  }
  for (int i = 1; i <= n; i++) {
    int fy, x;
    cin >> fy;
    while (fy--) {
      cin >> x;
      s[i].insert(x);
    }
  }
  for (int i = 1; i <= n; i++) dist[i] = 1 << 30;
  dist[1] = 0;
  q.push(make_pair(0, 1));
  while (!q.empty()) {
    int p = q.top().second;
    int to = -q.top().first;
    q.pop();
    if (to != dist[p]) continue;
    while (s[p].count(to)) to++;
    for (__typeof((e[p]).begin()) it = (e[p]).begin(); it != (e[p]).end(); it++)
      if (to + it->l < dist[it->k]) {
        dist[it->k] = to + it->l;
        q.push(make_pair(-dist[it->k], it->k));
      }
  }
  if (dist[n] == 1 << 30)
    cout << "-1";
  else
    cout << dist[n];
  return 0;
}
