#include <bits/stdc++.h>
using namespace std;
long long int n, m, k, x, y, z;
bool sortbysec(const pair<long long int, long long int> &a,
               const pair<long long int, long long int> &b) {
  return (a.second < b.second);
}
bool sortbyfi(const pair<long double, pair<long double, long double>> &a,
              const pair<long double, pair<long double, long double>> &b) {
  return (a.first > b.first);
}
vector<std::pair<long long int, long long int>> adj[100005];
vector<long long int> visited(100005), d(100005), p(100005), wait(100005);
vector<set<long long int>> s(100005);
void dijkstra(long long int src, long long int des) {
  for (long long int i = 1; i <= n; i++) {
    d[i] = 100000000000;
    p[i] = 0;
    wait[i] = 0;
    visited[i] = 0;
  }
  d[src] = 0;
  set<std::pair<long long int, long long int>> q;
  q.insert({0, src});
  while (!q.empty()) {
    long long int v = q.begin()->second;
    q.erase(q.begin());
    visited[v] = 1;
    while (s[v].find(d[v] + wait[v]) != s[v].end()) wait[v]++;
    for (auto edge : adj[v]) {
      long long int to = edge.first;
      long long int len = edge.second;
      if (d[v] + wait[v] + len < d[to]) {
        q.erase({d[to], to});
        d[to] = d[v] + len + wait[v];
        p[to] = v;
        q.insert({d[to], to});
      }
    }
  }
  if (!visited[des]) {
    cout << -1;
    return;
  }
  cout << d[des] << "\n";
}
void solve() {
  cin >> n >> m;
  for (long long int i = 0; i < m; i++) {
    cin >> x >> y >> z;
    adj[x].push_back({y, z});
    adj[y].push_back({x, z});
  }
  for (long long int i = 1; i <= n; i++) {
    cin >> x;
    while (x--) {
      cin >> y;
      s[i].insert(y);
    }
  }
  dijkstra(1, n);
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
