#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, w;
vector<pair<int, int> > adj[100002];
vector<int> dist(100002, INT_MAX);
vector<int> visit(100002, 0);
vector<int> p[100002];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    pq;
int find(int u, int d) {
  int s = 0;
  int e = p[u].size() - 1;
  int mid, ans = -1;
  while (s <= e) {
    mid = s + (e - s) / 2;
    if (p[u][mid] == d) {
      ans = mid;
      break;
    } else if (p[u][mid] < d)
      s = mid + 1;
    else
      e = mid - 1;
  }
  return ans;
}
void solve() {
  dist[1] = 0;
  pq.push({0, 1});
  while (!pq.empty()) {
    int u = pq.top().second;
    int d = pq.top().first;
    pq.pop();
    if (u == n) break;
    if (visit[u] == 1) {
      ;
    } else {
      int j = find(u, d);
      while (j != -1) {
        d += 1;
        j = find(u, d);
      }
      dist[u] = d;
      visit[u] = 1;
      for (int k = 0; k < adj[u].size(); k++) {
        int v = adj[u][k].first;
        w = adj[u][k].second;
        if (visit[v] == 0 && dist[u] != INT_MAX && dist[u] + w < dist[v]) {
          dist[v] = dist[u] + w;
          pq.push({dist[v], v});
        }
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> w;
    adj[a].push_back({b, w});
    adj[b].push_back({a, w});
  }
  for (int i = 1; i <= n; i++) {
    cin >> a;
    for (int j = 0; j < a; j++) {
      cin >> b;
      p[i].push_back(b);
    }
  }
  solve();
  if (dist[n] == INT_MAX)
    cout << -1;
  else
    cout << dist[n];
  return 0;
}
