#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
long long range[100001];
vector<vector<pair<int, int> > > A, Bp;
vector<int> B;
int n, m;
void solve(int time) {
  for (int i = 1; i <= n; ++i) {
    range[i] = INF;
  }
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  q.push(make_pair(time, 1));
  while (!q.empty()) {
    pair<int, int> temp = q.top();
    q.pop();
    if (temp.first >= range[temp.second]) continue;
    range[temp.second] = temp.first;
    for (int i = 0; i < A[temp.second].size(); ++i) {
      int to = A[temp.second][i].first;
      int mustbeat = temp.first + A[temp.second][i].second;
      if (to != n) {
        while (B[to] >= 0 && Bp[to][B[to]].first > mustbeat) {
          --B[to];
        }
        if (B[to] >= 0 && Bp[to][B[to]].first <= mustbeat &&
            Bp[to][B[to]].second >= mustbeat) {
          mustbeat = Bp[to][B[to]].second + 1;
        }
      }
      if (mustbeat < range[to]) {
        q.push(make_pair(mustbeat, to));
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  A.resize(n + 1, vector<pair<int, int> >());
  B.resize(n + 1);
  Bp.resize(n + 1);
  for (int i = 0; i < m; ++i) {
    int a, b, t;
    cin >> a >> b >> t;
    A[a].push_back(make_pair(b, t));
    A[b].push_back(make_pair(a, t));
  }
  int start = -1, finish = -1;
  for (int i = 1; i <= n; ++i) {
    int k;
    cin >> k;
    start = -1, finish = -1;
    for (int j = 0; j < k; ++j) {
      int temp;
      cin >> temp;
      if (start == -1)
        start = finish = temp;
      else {
        if (finish == temp - 1)
          ++finish;
        else {
          Bp[i].push_back(make_pair(start, finish));
          start = finish = temp;
        }
      }
    }
    if (start != -1) Bp[i].push_back(make_pair(start, finish));
    B[i] = Bp[i].size() - 1;
  }
  start = 0;
  while (B[1] >= 0 && Bp[1][B[1]].first > start) {
    --B[1];
  }
  if (B[1] >= 0 && Bp[1][B[1]].first <= start && Bp[1][B[1]].second >= start) {
    start = Bp[1][B[1]].second + 1;
  }
  solve(start);
  if (range[n] == INF)
    cout << -1;
  else
    cout << range[n];
  return 0;
}
