#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 5;
const long long inf = (long long)1e16;
int n, m;
set<long long> s[N];
vector<pair<int, long long> > g[N];
set<pair<long long, int> > q;
long long d[N];
int p[N];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int a, b, w;
    scanf("%d %d %d", &a, &b, &w);
    g[a].push_back(make_pair(b, w));
    g[b].push_back(make_pair(a, w));
  }
  for (int i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      int t;
      scanf("%d", &t);
      s[i].insert(t);
    }
  }
  for (int i = 1; i < N; i++) d[i] = inf;
  int st = 1;
  d[st] = 0;
  q.insert(make_pair(d[st], st));
  while (!q.empty()) {
    int v = (int)q.begin()->second;
    q.erase(q.begin());
    long long wait = 0;
    while (s[v].count(d[v] + wait) > 0) wait++;
    for (int i = 0; i < (int)g[v].size(); i++) {
      int to = (int)g[v][i].first;
      long long len = (long long)g[v][i].second;
      if (d[v] + len + wait < d[to]) {
        q.erase(make_pair(d[to], to));
        d[to] = d[v] + len + wait;
        q.insert(make_pair(d[to], to));
        p[to] = v;
      }
    }
  }
  long long res = d[n] == inf ? -1 : d[n];
  cout << res;
  return 0;
}
