#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
const int inf = 0x3f3f3f3f;
int head[maxn], vis[maxn], dis[maxn], k, la[maxn], n;
vector<int> t[maxn], d[maxn];
int read() {
  int ret = 0, sig = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') sig = 1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    ret = (ret << 3) + (ret << 1) + ch - 48;
    ch = getchar();
  }
  if (sig) return -ret;
  return ret;
}
struct node {
  int v, w, nxt;
} e[maxn << 1];
void Adde(int u, int v, int w) {
  e[k].v = v;
  e[k].w = w;
  e[k].nxt = head[u];
  head[u] = k++;
}
int Cal(int u, int nt) {
  for (int i = 0; i < la[u]; ++i) {
    if (nt < t[u][i]) break;
    if (nt == t[u][i]) nt++;
  }
  return nt;
}
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    q;
void dijkstra() {
  dis[1] = 0;
  q.push(make_pair(0, 1));
  while (!q.empty()) {
    int u = q.top().second;
    q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    int wt = Cal(u, dis[u]);
    for (int i = head[u]; i != -1; i = e[i].nxt) {
      int v = e[i].v;
      if (dis[v] > wt + e[i].w) {
        dis[v] = wt + e[i].w;
        q.push(make_pair(dis[v], v));
      }
    }
  }
}
int m, a, b, c, tmp[maxn];
int main() {
  memset(head, -1, sizeof(head));
  memset(dis, inf, sizeof(dis));
  n = read();
  m = read();
  for (int i = 1; i <= m; ++i) {
    a = read();
    b = read();
    c = read();
    Adde(a, b, c);
    Adde(b, a, c);
  }
  for (int i = 1; i <= n; ++i) {
    la[i] = read();
    for (int j = 0; j < la[i]; ++j) t[i].push_back(read());
  }
  dijkstra();
  if (dis[n] == inf)
    printf("-1\n");
  else
    printf("%d\n", dis[n]);
  return 0;
}
