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