#include <bits/stdc++.h>
using namespace std;
void solve();
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed;
  cout.precision(12);
  solve();
  return 0;
}
template <typename T>
void prv(vector<T> v) {
  for (int __ii = 0; __ii < ((int)v.size()); __ii++) {
    if (__ii) cout << ' ';
    cout << v[__ii];
  }
  cout << '\n';
}
template <typename T>
void prm(vector<vector<T>> v) {
  for (int __ii = 0; __ii < ((int)v.size()); __ii++) {
    for (int __jj = 0; __jj < v[__ii].size(); __jj++) {
      if (__jj) cout << ' ';
      cout << v[__ii][__jj];
    }
    cout << '\n';
  }
}
template <typename T>
void sc(T& x) {
  cin >> x;
}
template <typename Head, typename... Tail>
void sc(Head& head, Tail&... tail) {
  cin >> head;
  sc(tail...);
}
template <typename T>
void pr(const T& x) {
  cout << x << '\n';
}
template <typename Head, typename... Tail>
void pr(const Head& head, const Tail&... tail) {
  cout << head << ' ';
  pr(tail...);
}
template <typename... T>
void err(const T&... cod) {
  pr(cod...);
  exit(0);
}
void solve() {
  int n, m;
  sc(n, m);
  vector<vector<pair<int, int>>> g(n);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    sc(u, v, w);
    u--;
    v--;
    g[u].emplace_back(v, w);
    g[v].emplace_back(u, w);
  }
  vector<map<int, int>> make_pair(n);
  for (int i = 0; i < n; i++) {
    int k;
    sc(k);
    vector<int> t(k);
    for (int __ii = 0; __ii < k; __ii++) cin >> t[__ii];
    sort(t.begin(), t.end());
    {
      int p = 0;
      while (p < ((int)t.size())) {
        int q = p + 1;
        while (q < ((int)t.size()) && t[q] == t[q - 1] + 1) {
          q++;
        }
        while (p < q) {
          make_pair[i][t[p]] = q - p;
          p++;
        }
      }
    }
  }
  priority_queue<pair<int, int>> pq;
  int t = 0;
  if (make_pair[0].count(t)) t += make_pair[0][t];
  pq.emplace(-t, 0);
  vector<int> dist(n, -1);
  dist[0] = t;
  while (!pq.empty()) {
    pair<int, int> p = pq.top();
    pq.pop();
    int u = p.second, d = p.first;
    d *= -1;
    assert(dist[u] != -1);
    if (d > dist[u]) continue;
    for (auto p : g[u]) {
      int v = p.first, w = p.second;
      if (v != n - 1 && make_pair[v].count(d + w)) w += make_pair[v][d + w];
      if (dist[v] == -1 || d + w < dist[v]) {
        dist[v] = d + w;
        pq.emplace(-dist[v], v);
      }
    }
  }
  pr(dist[n - 1]);
}
