#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > a[100005];
set<int> delay[100005];
long long dist[100005];
set<int>::iterator it;
void dijkstra() {
  bool f[100005];
  for (int i = 0; i < n; i++) f[i] = false;
  for (int i = 0; i < n; i++) dist[i] = 999999999999999999;
  dist[0] = 0;
  priority_queue<pair<int, int> > sar;
  sar.push({0, 0});
  while (!sar.empty()) {
    int u = sar.top().second;
    long long d = -sar.top().first;
    sar.pop();
    if (f[u]) continue;
    f[u] = true;
    long long time = d;
    it = delay[u].find(time);
    while (it != delay[u].end() && (*it) == time) {
      it++;
      time++;
    }
    for (int i = 0; i < a[u].size(); i++) {
      if (f[a[u][i].first]) continue;
      if (dist[a[u][i].first] > time + a[u][i].second) {
        dist[a[u][i].first] = time + a[u][i].second;
        sar.push({-dist[a[u][i].first], a[u][i].first});
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v, d;
    cin >> u >> v >> d;
    u--;
    v--;
    a[u].push_back({v, d});
    a[v].push_back({u, d});
  }
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int x;
      cin >> x;
      delay[i].insert(x);
    }
  }
  dijkstra();
  if (dist[n - 1] == 999999999999999999) {
    cout << "-1";
    return 0;
  }
  cout << dist[n - 1];
}
