#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 123;
const int mod = 1e9 + 7;
const int INF = 1e9 + 1;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, m;
vector<pair<int, int> > g[MAXN];
set<pair<long long, int> > q;
long long d[MAXN];
map<int, bool> cnt[MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  while (m--) {
    int u, v, c;
    cin >> u >> v >> c;
    g[u].push_back(make_pair(c, v));
    g[v].push_back(make_pair(c, u));
  }
  for (int i = 1; i <= n; i++) {
    d[i] = INF * 1ll * INF;
    int k;
    cin >> k;
    for (int j = 1; j <= k; j++) {
      int x;
      cin >> x;
      cnt[i][x] = 1;
    }
  }
  d[1] = 0;
  q.insert(make_pair(0, 1));
  while (!q.empty()) {
    int v = q.begin()->second;
    q.erase(q.begin());
    long long t = d[v];
    while (cnt[v][t]) {
      t++;
    }
    for (int i = 0; i < g[v].size(); i++) {
      long long to = g[v][i].second;
      if (g[v][i].first + t < d[to]) {
        q.erase(make_pair(d[to], to));
        d[to] = g[v][i].first + t;
        q.insert(make_pair(d[to], to));
      }
    }
  }
  cout << (d[n] == INF * 1ll * INF ? -1 : d[n]);
  return 0;
}
