#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> d(n + 1, 1e12);
  vector<vector<pair<long long, long long> > > G(n + 1);
  for (long long i = 0; i < (long long)(m); i++) {
    long long a, b, w;
    cin >> a >> b >> w;
    G[a].push_back({b, w});
    G[b].push_back({a, w});
  }
  set<pair<long long, long long> > och;
  d[1] = 0;
  for (long long i = 1; i <= (long long)(n); i++) och.insert({d[i], i});
  vector<vector<long long> > ban(n + 1);
  vector<map<long long, long long> > ok(n + 1);
  for (long long i = 1; i <= (long long)(n); i++) {
    long long s;
    cin >> s;
    for (long long j = 0; j < (long long)(s); j++) {
      long long d;
      cin >> d;
      ban[i].push_back(d);
    }
  }
  for (long long u = 1; u <= (long long)(n); u++)
    if (ban[u].size() > 0) {
      long long okkk = ban[u].back() + 1;
      ok[u][ban[u].back()] = okkk;
      for (long long i = (long long)ban[u].size() - 2; i >= 0; i--) {
        if (ban[u][i] != ban[u][i + 1] - 1) okkk = ban[u][i] + 1;
        ok[u][ban[u][i]] = okkk;
      }
    }
  for (long long u = 0; u < (long long)(n); u++) {
    pair<long long, long long> b = *(och.begin());
    long long ver, w;
    ver = b.second;
    w = b.first;
    if (ok[ver][w] != 0) w = ok[ver][w];
    for (long long i = 0; i < (long long)(G[ver].size()); i++) {
      long long to = G[ver][i].first;
      long long we = G[ver][i].second;
      long long sum = w + we;
      if (d[to] > sum) {
        och.erase({d[to], to});
        d[to] = sum;
        och.insert({d[to], to});
      }
    }
    och.erase(och.begin());
  }
  if (d[n] == 1e12)
    cout << -1;
  else
    cout << d[n];
}
