#include <bits/stdc++.h>
using namespace std;
const long long inf = 2e9;
const long long N = 1e5 + 100;
const long long bits = 20;
const long long mod = 1e9 + 7;
const long double pi = 3.14159265358979323846;
vector<int> adj[N], w[N];
set<int> k[N];
int dist[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  std::cout << std::fixed << std::setprecision(20);
  ;
  int n, m, u, v, c;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> c;
    adj[u].push_back(v);
    adj[v].push_back(u);
    w[u].push_back(c);
    w[v].push_back(c);
  }
  int sz, temp;
  for (int i = 1; i <= n; i++) {
    cin >> sz;
    while (sz--) {
      cin >> temp;
      k[i].insert(temp);
    }
    dist[i] = inf;
  }
  priority_queue<pair<int, int>> pq;
  dist[1] = 0;
  pq.push({-dist[1], 1});
  while (!pq.empty()) {
    int node = pq.top().second;
    int d = -pq.top().first;
    pq.pop();
    while (k[node].find(d) != k[node].end()) d++;
    for (int i = 0; i < adj[node].size(); i++) {
      int nxt = adj[node][i];
      int nd = d + w[node][i];
      if (dist[nxt] > nd) {
        dist[nxt] = nd;
        pq.push({-nd, nxt});
      }
    }
  }
  if (dist[n] == inf) {
    cout << -1;
  } else {
    cout << dist[n];
  }
}
