#include <bits/stdc++.h>
using namespace std;
const int MAXV = 100005, oo = (int)1e9 + (int)1e9;
struct edge {
  int v, w;
  edge(){};
  edge(int vv, int ww) {
    v = vv;
    w = ww;
  };
  bool operator<(const edge& X) const { return w > X.w; }
};
bool mark[MAXV];
vector<int> T[MAXV];
vector<edge> G[MAXV];
int V, P, K, dist[MAXV];
int BSearch(int nod, int num) {
  int large = T[nod].size();
  if (large == 0) return num;
  if (T[nod][0] > num) return num;
  if (T[nod][large - 1] < num) return num;
  int izq = 0, der = large - 1, med;
  while (1) {
    if (T[nod][izq] >= num) break;
    med = (izq + der) >> 1;
    if (T[nod][med] < num)
      izq = med + 1;
    else
      der = med;
  }
  int tnum = num;
  while (izq < large && T[nod][izq] == tnum) {
    izq++;
    tnum++;
  }
  return tnum;
}
void dijkstradist(int src) {
  fill(dist, dist + V + 1, oo);
  fill(mark, mark + V + 1, false);
  dist[src] = BSearch(src, 0);
  int best, distt, limit, tmpv;
  priority_queue<edge> pcola;
  pcola.push(edge(src, dist[src]));
  while (!pcola.empty()) {
    edge aux = pcola.top();
    pcola.pop();
    if (mark[aux.v]) continue;
    mark[aux.v] = true;
    best = aux.v;
    limit = G[best].size() - 1;
    for (int j = (0); j <= (limit); j += (1)) {
      int Z = G[best][j].v;
      if (!mark[Z]) {
        distt = aux.w + G[best][j].w;
        if (distt < dist[Z]) {
          dist[Z] = distt;
          distt = BSearch(Z, distt);
          pcola.push(edge(Z, distt));
        }
      }
    }
  }
}
int main() {
  int u, v, w, t;
  scanf("%d%d", &V, &P);
  for (int p = (1); p <= (V); p += (1)) {
    G[p].clear();
    T[p].clear();
  }
  for (int i = (1); i <= (P); i += (1)) {
    scanf("%d%d%d", &u, &v, &w);
    G[u].push_back(edge(v, w));
    G[v].push_back(edge(u, w));
  }
  for (int p = (1); p <= (V); p += (1)) {
    scanf("%d", &K);
    for (int i = (1); i <= (K); i += (1)) {
      scanf("%d", &t);
      T[p].push_back(t);
    }
  }
  dijkstradist(1);
  if (dist[V] == oo) printf("-1");
  if (dist[V] != oo) printf("%d", dist[V]);
}
