#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
const long long N = 1e5 + 5;
long long n, m, x, y, z, d[N], vis[N];
vector<pair<long long, long long>> v[N];
vector<long long> a[N];
multiset<pair<long long, long long>> s;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    cin >> x >> y >> z;
    v[x].push_back({y, z}), v[y].push_back({x, z});
  }
  for (long long i = 1; i <= n; i++) {
    cin >> x, a[i].resize(x), d[i] = 1e12;
    for (long long j = 0; j < x; j++) cin >> a[i][j];
  }
  d[1] = 0;
  for (long long i = 1; i <= n; i++) s.insert({d[i], i});
  while (s.size()) {
    pair<long long, long long> p = *s.begin();
    z = p.first, x = p.second, s.erase(s.begin());
    if (vis[x]) continue;
    vis[x] = 1;
    for (auto &i : a[x])
      if (i == z) z++;
    for (auto &i : v[x])
      if (!vis[i.first] and z + i.second < d[i.first])
        s.erase({d[i.first], i.first}), d[i.first] = z + i.second,
                                        s.insert({d[i.first], i.first});
  }
  if (d[n] == 1e12) d[n] = -1;
  cout << d[n];
  return 0;
}
