#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void desperate_optimization(bool submitting = true,
                            long long int precision = 10) {
  if (!submitting) return;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(precision);
}
const long long int maxn = 112345;
vector<pair<long long int, long long int>> edges[maxn];
vector<long long int> banned[maxn];
set<long long int> bannedset[maxn];
const long long int inf = 1e18 + 5;
int32_t main() {
  desperate_optimization(true);
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 0; i < m; i++) {
    long long int u, v, w;
    cin >> u >> v >> w;
    edges[u].push_back({v, w});
    edges[v].push_back({u, w});
  }
  for (long long int i = 1; i <= n; i++) {
    long long int count;
    cin >> count;
    while (count--) {
      long long int val;
      cin >> val;
      banned[i].push_back(val);
      bannedset[i].insert(val);
    }
    if (banned[i].size() == 0) continue;
    vector<long long int> temp;
    for (long long int j = 0; j < banned[i].size() - 1; j++) {
      if (banned[i][j] + 1 != banned[i][j + 1])
        temp.push_back(banned[i][j] + 1);
    }
    temp.push_back(banned[i][banned[i].size() - 1] + 1);
    banned[i] = temp;
  }
  vector<long long int> distance(n + 1, inf);
  distance[1] = 0;
  priority_queue<pair<long long int, long long int>> pq;
  pq.push({0, 1});
  while (pq.size()) {
    auto z = pq.top();
    z.first *= -1;
    pq.pop();
    if (z.first > distance[z.second]) continue;
    for (auto itr : edges[z.second]) {
      long long int departuretime = z.first;
      if (banned[z.second].size()) {
        if (bannedset[z.second].count(z.first)) {
          auto index = lower_bound(banned[z.second].begin(),
                                   banned[z.second].end(), z.first) -
                       banned[z.second].begin();
          if (index != banned[z.second].size())
            departuretime = banned[z.second][index];
        }
      }
      long long int arrivaltime = departuretime + itr.second;
      long long int destination = itr.first;
      if (distance[destination] > arrivaltime) {
        distance[destination] = arrivaltime;
        pq.push({-arrivaltime, destination});
      }
    }
  }
  if (distance[n] == inf)
    cout << "-1";
  else
    cout << distance[n];
  return 0;
}
