#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int inf = 0x3f3f3f3f;
int a, b, c, n, m, k, t, d[maxn];
set<int> st[maxn];
vector<pair<int, int> > vec[maxn];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    que;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &a, &b, &c);
    vec[a].push_back(pair<int, int>(b, c));
    vec[b].push_back(pair<int, int>(a, c));
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &k);
    while (k--) {
      scanf("%d", &t);
      st[i].insert(t);
    }
  }
  memset(d, 0x3f, sizeof d);
  d[1] = 0;
  que.push(pair<int, int>(d[1], 1));
  while (!que.empty()) {
    int u = que.top().second, td = que.top().first;
    que.pop();
    if (td > d[u]) continue;
    int oo = 0;
    while (st[u].find(oo + d[u]) != st[u].end()) ++oo;
    for (unsigned int i = 0; i < vec[u].size(); ++i) {
      int v = vec[u][i].first, o = vec[u][i].second;
      if (d[v] > d[u] + o + oo) {
        d[v] = d[u] + o + oo;
        que.push(pair<int, int>(d[v], v));
      }
    }
  }
  printf("%d\n", d[n] == inf ? -1 : d[n]);
  return 0;
}
