#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, long long int>> adj[100005];
vector<long long int> ent[100005];
long long int dist[100005];
pair<long long int, long long int> segtree[400005];
void build(long long int t, long long int tl, long long int tr) {
  if (tl == tr) {
    segtree[t] = make_pair(dist[tl], tl);
    return;
  }
  long long int tm = (tl + tr) / 2;
  build(2 * t, tl, tm);
  build(2 * t + 1, tm + 1, tr);
  segtree[t] = segtree[2 * t].first <= segtree[2 * t + 1].first
                   ? segtree[2 * t]
                   : segtree[2 * t + 1];
  return;
}
void update(long long int t, long long int tl, long long int tr,
            long long int pos, long long int val) {
  if (tl == tr) {
    segtree[t].first = val;
    return;
  }
  long long int tm = (tl + tr) / 2;
  if (pos <= tm)
    update(2 * t, tl, tm, pos, val);
  else
    update(2 * t + 1, tm + 1, tr, pos, val);
  segtree[t] = segtree[2 * t].first <= segtree[2 * t + 1].first
                   ? segtree[2 * t]
                   : segtree[2 * t + 1];
  return;
}
long long int query(long long int t, long long int tl, long long int tr,
                    long long int pos) {
  if (tl == tr) return segtree[t].first;
  long long int tm = (tl + tr) / 2;
  if (pos <= tm)
    return query(2 * t, tl, tm, pos);
  else
    return query(2 * t + 1, tm + 1, tr, pos);
}
long long int check(long long int i, long long int t) {
  long long int ans = t;
  for (auto it : ent[i]) {
    if (it == ans) ans++;
    if (it > ans) break;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 0; i < m; i++) {
    long long int a, b, c;
    cin >> a >> b >> c;
    adj[a].push_back(make_pair(b, c));
    adj[b].push_back(make_pair(a, c));
  }
  for (long long int i = 1; i <= n; i++) {
    long long int k;
    cin >> k;
    for (long long int j = 1; j <= k; j++) {
      long long int a;
      cin >> a;
      ent[i].push_back(a);
    }
  }
  for (long long int i = 0; i < 100005; i++) dist[i] = 1000000000000000000;
  build(1, 1, n);
  dist[1] = 0;
  long long int a = check(1, dist[1]);
  for (auto it : adj[1]) update(1, 1, n, it.first, a + it.second);
  for (long long int i = 1; i < n; i++) {
    long long int c = segtree[1].first;
    long long int d = segtree[1].second;
    dist[d] = c;
    update(1, 1, n, d, 1000000000000000000);
    a = check(d, c);
    for (auto it : adj[d]) {
      if (dist[it.first] == 1000000000000000000) {
        if (query(1, 1, n, it.first) > a + it.second)
          update(1, 1, n, it.first, a + it.second);
      }
    }
  }
  if (dist[n] == 1000000000000000000)
    cout << -1 << '\n';
  else
    cout << dist[n] << '\n';
  return 0;
}
