#include <bits/stdc++.h>
using namespace std;
int n, m, u, v, w, k, del, st, ed, mid;
long long Di, dist[100005], curw;
vector<vector<pair<long long, int> > > ver;
vector<vector<int> > delay;
set<pair<long long, int> > sgate;
pair<long long, int> cur;
int WTraveller(int x, int time) {
  st = 0, ed = delay[x].size() - 1;
  if (ed == -1) return 0;
  while (st <= ed) {
    mid = st + (ed - st) / 2;
    if (delay[x][mid] == time)
      return 1;
    else if (delay[x][mid] < time)
      st = mid + 1;
    else
      ed = mid - 1;
  }
  return 0;
}
long long Dijkstra(int x, int y) {
  sgate.insert({x, y});
  dist[y] = 0;
  while (!sgate.empty()) {
    cur = *sgate.begin();
    sgate.erase(sgate.begin());
    curw = cur.first;
    while (WTraveller(cur.second, curw)) ++curw;
    for (int i = 0; i < ver[cur.second].size(); ++i) {
      if (curw + ver[cur.second][i].first < dist[ver[cur.second][i].second]) {
        dist[ver[cur.second][i].second] = curw + ver[cur.second][i].first;
        sgate.insert(
            {dist[ver[cur.second][i].second], ver[cur.second][i].second});
      }
    }
  }
  if (dist[n] == 1e12) return -1;
  return dist[n];
}
int main() {
  cin >> n >> m;
  ver.resize(n + 1), delay.resize(n + 1);
  for (int i = 2; i <= n; ++i) dist[i] = 1e12;
  for (int i = 1; i <= m; ++i) {
    cin >> u >> v >> w;
    ver[u].push_back({w, v});
    ver[v].push_back({w, u});
  }
  for (int i = 1; i <= n; ++i) {
    cin >> k;
    for (int j = 0; j < k; ++j) {
      cin >> del;
      delay[i].push_back(del);
    }
  }
  Di = Dijkstra(0, 1);
  cout << Di << endl;
}
