#include <bits/stdc++.h>
using namespace std;
struct node {
  int id, c;
  bool operator<(node x) const { return c > x.c; }
} tp, z;
vector<node> t[100010], pt[100010];
priority_queue<node> q;
int mk[100010];
int findtime(int nd, int tt) {
  int l = t[nd].size();
  if (l <= 0) return -1;
  if (tt < t[nd][0].id) return -1;
  if (tt == t[nd][0].id) return 0;
  if (tt > t[nd][l - 1].id) return -1;
  if (tt == t[nd][l - 1].id) return l - 1;
  int left = 0, right = l - 1;
  while (left <= right) {
    int mid = (left + right) / 2;
    if (t[nd][mid].id == tt) return mid;
    if (tt < t[nd][mid].id)
      right = mid - 1;
    else if (t[nd][mid].id < tt)
      left = mid + 1;
  }
  return -1;
}
int main() {
  int n, m;
  while (scanf("%d %d", &n, &m) != EOF) {
    for (int i = 1; i <= n; i++) {
      pt[i].clear();
      t[i].clear();
      mk[i] = 2000000000;
    }
    int a, b, c;
    while (m--) {
      scanf("%d %d %d", &a, &b, &c);
      tp.id = a;
      tp.c = c;
      pt[b].push_back(tp);
      tp.id = b;
      pt[a].push_back(tp);
    }
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a);
      tp.c = 1;
      for (int j = 0; j < a; j++) {
        scanf("%d", &tp.id);
        t[i].push_back(tp);
      }
      for (int j = a - 2; j >= 0; j--) {
        if (t[i][j].id + 1 == t[i][j + 1].id) t[i][j].c = t[i][j + 1].c + 1;
      }
    }
    tp.id = 1;
    tp.c = 0;
    while (!q.empty()) q.pop();
    q.push(tp);
    while (!q.empty()) {
      tp = q.top();
      q.pop();
      if (tp.c > mk[n]) break;
      int pp = findtime(tp.id, tp.c);
      if (pp >= 0) tp.c += t[tp.id][pp].c;
      int l = pt[tp.id].size();
      for (int i = 0; i < l; i++) {
        if (tp.c + pt[tp.id][i].c < mk[pt[tp.id][i].id]) {
          z.id = pt[tp.id][i].id;
          z.c = tp.c + pt[tp.id][i].c;
          mk[z.id] = z.c;
          q.push(z);
        }
      }
    }
    if (mk[n] < 2000000000)
      printf("%d\n", mk[n]);
    else
      puts("-1");
  }
  return 0;
}
