#include <bits/stdc++.h>
using namespace std;
struct trans {
  int b, c;
  trans(int _b, int _c) : b(_b), c(_c) {}
};
vector<trans> a[100000];
vector<int> t[100000];
size_t tp[100000];
int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int ai, bi, ci;
    scanf("%d%d%d", &ai, &bi, &ci);
    a[ai - 1].push_back(trans(bi - 1, ci));
    a[bi - 1].push_back(trans(ai - 1, ci));
  }
  for (int i = 0; i < n; i++) {
    int k;
    scanf("%d", &k);
    t[i].reserve(k);
    for (int j = 0; j < k; j++) {
      int tij;
      scanf("%d", &tij);
      t[i].push_back(tij);
    }
  }
  vector<int> d(n, INT_MAX);
  set<pair<int, int> > q;
  q.insert(make_pair(0, 0));
  d[0] = 0;
  while (!q.empty()) {
    int i = q.begin()->second;
    q.erase(q.begin());
    while (tp[i] < t[i].size() && t[i][tp[i]] < d[i]) {
      tp[i]++;
    }
    int st = d[i];
    while (tp[i] < t[i].size() && t[i][tp[i]] == st) {
      st++;
      tp[i]++;
    }
    for (vector<trans>::iterator j = a[i].begin(); j != a[i].end(); j++) {
      if (st + j->c < d[j->b]) {
        q.erase(make_pair(d[j->b], j->b));
        d[j->b] = st + j->c;
        q.insert(make_pair(d[j->b], j->b));
      }
    }
  }
  if (d[n - 1] == INT_MAX)
    printf("-1");
  else
    printf("%d", d[n - 1]);
}
