#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i = i + 6) {
    if (n % i == 0 || n % (i + 2) == 0) return false;
  }
  return true;
}
long long po(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
bool sec(const pair<long long, long long> &a,
         const pair<long long, long long> &b) {
  if (a.second == b.second) return a.first > b.first;
  return a.second > b.second;
}
long long find(long long x, vector<vector<pair<long long, long long> > > ne,
               long long i) {
  if (ne[i].size() == 0) return -1;
  long long l = 0, h = ne[i].size() - 1, m;
  while (l <= h) {
    m = (l + h) / 2;
    if (ne[i][m].first < x)
      l = m + 1;
    else if (ne[i][m].first > x)
      h = m - 1;
    else
      return m;
  }
  return -1;
}
void dij(long long second, vector<vector<pair<long long, long long> > > &v,
         vector<long long> &vis, long long dis[],
         vector<set<pair<long long, long long> > > se) {
  set<pair<long long, long long> >::iterator it;
  dis[1] = 0;
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      p;
  p.push(make_pair(0, 1));
  long long i, x, w, wi, e, in;
  while (!p.empty()) {
    x = p.top().second;
    p.pop();
    if (vis[x]) continue;
    vis[x] = 1;
    it = se[x].lower_bound(make_pair(dis[x], -LONG_LONG_MAX));
    if (it == se[x].end() || it->first != dis[x])
      w = 0;
    else
      w = it->second;
    for (i = 0; i < v[x].size(); i++) {
      e = v[x][i].first, wi = v[x][i].second;
      if (dis[x] + wi + w < dis[e]) {
        dis[e] = dis[x] + w + wi;
        p.push(make_pair(dis[e], e));
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long n, m, i, x, y, w, j;
  cin >> n >> m;
  vector<vector<pair<long long, long long> > > v(n + 1), ne(n + 1);
  vector<set<pair<long long, long long> > > se(n + 1);
  vector<long long> vis(n + 1);
  long long dis[n + 1];
  fill_n(dis, n + 1, LONG_LONG_MAX);
  for (i = 0; i < m; i++) {
    cin >> x >> y >> w;
    v[x].push_back(make_pair(y, w));
    v[y].push_back(make_pair(x, w));
  }
  for (i = 1; i < n + 1; i++) {
    cin >> x;
    for (j = 0; j < x; j++) {
      cin >> y;
      ne[i].push_back(make_pair(y, 0));
    }
    for (j = x - 1; j > -1; j--) {
      if (j == x - 1)
        ne[i][j].second = 1;
      else {
        if (ne[i][j].first + 1 == ne[i][j + 1].first)
          ne[i][j].second = 1 + ne[i][j + 1].second;
        else
          ne[i][j].second = 1;
      }
    }
    se[i].insert(ne[i].begin(), ne[i].end());
  }
  dij(1, v, vis, dis, se);
  vis[n] ? cout << dis[n] : cout << "-1";
}
