#include <bits/stdc++.h>
using namespace std;
int main() {
  int planets, gates;
  cin >> planets >> gates;
  vector<vector<pair<int, int> > > adj(planets + 1);
  int x, y, z;
  for (int i = 0; i < gates; i++) {
    cin >> x >> y >> z;
    adj[x].push_back(make_pair(y, z));
    adj[y].push_back(make_pair(x, z));
  }
  vector<map<int, int> > arrive(planets + 1, map<int, int>());
  vector<int> tmp;
  for (int i = 1; i <= planets; i++) {
    cin >> x;
    if (!x) continue;
    tmp = vector<int>(x);
    for (int j = 0; j < x; j++) {
      cin >> y;
      tmp[j] = y;
    }
    z = 1;
    arrive[i][tmp[x - 1]] = 1;
    for (int j = x - 2; j >= 0; j--) {
      if (tmp[j + 1] - tmp[j] == 1)
        z++;
      else
        z = 1;
      arrive[i][tmp[j]] = z;
    }
  }
  set<pair<int, int> > vertq;
  vector<int> dist(planets + 1, (2000000000));
  dist[1] = 0;
  if (arrive[1].count(dist[1]) > 0) dist[1] += arrive[1][0];
  vertq.insert(make_pair(dist[1], 1));
  int d, v, u;
  while (vertq.size() > 0) {
    v = vertq.begin()->second;
    vertq.erase(vertq.begin());
    for (vector<pair<int, int> >::iterator it = adj[v].begin();
         it != adj[v].end(); it++) {
      u = it->first;
      d = dist[v] + it->second;
      if (arrive[u].count(d) > 0 && u != planets) d += arrive[u][d];
      if (d < dist[u]) {
        vertq.erase(make_pair(dist[u], u));
        dist[u] = d;
        vertq.insert(make_pair(dist[u], u));
      }
    }
  }
  if (dist[planets] == (2000000000))
    cout << -1 << endl;
  else
    cout << dist[planets] << endl;
}
