#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > a[200020];
int d[200020];
map<pair<int, int>, int> mp;
int k, x, y, z;
set<pair<int, int> > q;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    a[x].push_back(make_pair(y, z));
    a[y].push_back(make_pair(x, z));
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      scanf("%d", &x);
      mp[make_pair(i, x)] = 1;
    }
  }
  int v, w, to, p, dx;
  for (int i = 1; i <= n; i++) d[i] = (1 << 30);
  d[1] = 0;
  q.insert(make_pair(0, 1));
  while (!q.empty()) {
    v = q.begin()->second;
    dx = q.begin()->first;
    if (d[v] != dx) continue;
    q.erase(q.begin());
    while (mp[make_pair(v, dx)] == 1) dx++;
    for (int j = 0; j < a[v].size(); j++) {
      to = a[v][j].first;
      w = a[v][j].second;
      if (d[to] > dx + w) {
        q.erase(make_pair(d[to], to));
        d[to] = dx + w;
        q.insert(make_pair(d[to], to));
      }
    }
  }
  if (d[n] == (1 << 30))
    cout << -1;
  else
    cout << d[n];
  return 0;
}
