#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100005;
const long long inf = 0x3f3f3f3f3f3f3f3f;
int n, m;
vector<pair<int, int> > g[Maxn];
unordered_set<int> t[Maxn];
long long dist[Maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    g[x].push_back(make_pair(y, z));
    g[y].push_back(make_pair(x, z));
  }
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    for (int j = 0, jend = x; j < jend; j++) {
      scanf("%d", &x);
      t[i].insert(x);
    }
  }
  memset(dist, 63, sizeof(dist));
  dist[1] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  for (q.push(make_pair(0, 1)); !q.empty(); q.pop()) {
    pair<int, int> cur = q.top();
    int d = cur.first, p = cur.second;
    if (dist[p] != d) continue;
    while (t[p].count(d)) d++;
    for (int i = 0; i < g[p].size(); i++) {
      pair<int, int> x = g[p][i];
      if (dist[x.first] > d + x.second) {
        dist[x.first] = d + x.second;
        q.push(make_pair(dist[x.first], x.first));
      }
    }
  }
  if (dist[n] == inf) return (int)puts("-1") * 0;
  printf("%d\n", dist[n]);
  return 0;
}
