#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const double EPS = 1e-9;
const long long MOD = 1e9 + 7;
const int MAXN = 1e5 + 20;
int n, m;
vector<pair<long long, long long> > v[MAXN];
vector<long long> h[MAXN];
vector<long long> len[MAXN];
long long dist[MAXN];
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    pq;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    v[a].push_back(make_pair(b, c));
    v[b].push_back(make_pair(a, c));
  }
  for (int i = 0; i < n; i++) {
    dist[i] = INF;
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      long long a;
      cin >> a;
      h[i].push_back(a);
      len[i].push_back(1);
    }
    for (int j = k - 1; j >= 0; j--) {
      if (h[i][j] == h[i][j + 1] - 1) {
        len[i][j] += len[i][j + 1];
      }
    }
  }
  int lol = 0;
  if (0 < h[0].size() && h[0][0] == lol) {
    lol += len[0][0];
  }
  dist[0] = lol;
  pq.push(make_pair(lol, 0));
  while (!pq.empty()) {
    pair<long long, long long> now = pq.top();
    pq.pop();
    if (now.first != dist[now.second]) continue;
    for (int i = 0; i < v[now.second].size(); i++) {
      pair<long long, long long> sek = v[now.second][i];
      if (sek.first != n - 1) {
        int it = lower_bound(h[sek.first].begin(), h[sek.first].end(),
                             now.first + sek.second) -
                 h[sek.first].begin();
        if (it != h[sek.first].size() &&
            h[sek.first][it] == now.first + sek.second) {
          sek.second += len[sek.first][it];
        }
      }
      if (dist[sek.first] > dist[now.second] + sek.second) {
        dist[sek.first] = dist[now.second] + sek.second;
        pq.push(make_pair(dist[sek.first], sek.first));
      }
    }
  }
  if (dist[n - 1] == INF)
    cout << -1 << '\n';
  else
    cout << dist[n - 1] << '\n';
}
