#include <bits/stdc++.h>
using namespace std;
int head[100005], idx;
struct Edge {
  int v, c, nt;
} e[100005 * 2];
long long dis[100005];
int n, m;
set<long long> s[100005];
struct node {
  int x;
  long long c;
  node() {}
  node(int x, long long c) : x(x), c(c) {}
  bool operator<(const node &w) const { return c > w.c; }
};
priority_queue<node> q;
void AddEdge(int u, int v, int c) {
  e[idx].v = v, e[idx].c = c, e[idx].nt = head[u], head[u] = idx++;
}
int main() {
  cin >> n >> m;
  idx = 1;
  for (int i = 0; i < m; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    AddEdge(u, v, c);
    AddEdge(v, u, c);
  }
  for (int i = 1; i <= n; i++) {
    dis[i] = -1;
    int k;
    long long t;
    cin >> k;
    while (k--) {
      cin >> t;
      s[i].insert(t);
    }
  }
  dis[1] = 0;
  q.push(node(1, 0));
  while (!q.empty()) {
    int u = q.top().x;
    long long c = q.top().c;
    q.pop();
    if (u == n) {
      cout << c << endl;
      return 0;
    }
    if (s[u].find(c) != s[u].end()) {
      q.push(node(u, c + 1));
      continue;
    }
    for (int i = head[u]; i; i = e[i].nt) {
      int v = e[i].v;
      if (dis[v] == -1 || dis[v] > e[i].c + c) {
        dis[v] = e[i].c + c;
        q.push(node(v, dis[v]));
      }
    }
  }
  cout << -1 << endl;
}
