#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<long long, long long>> adj[(int)1e5 + 1];
vector<long long> tim[(int)1e5 + 1];
long long tmm[(int)1e5 + 1];
long long arr[(int)1e5 + 1];
long long check[(int)1e5 + 1];
map<pair<long long, long long>, long long> r;
void dfs(long long x, long long time) {
  while (r[{x, time}]) {
    time++;
  }
  for (auto s : adj[x]) {
    if (time + s.second < tmm[s.first]) {
      tmm[s.first] = time + s.second;
      dfs(s.first, tmm[s.first]);
    }
  }
}
void solve() {
  queue<pair<long long, long long>> q;
  q.push({1, 0});
  while (!q.empty()) {
    auto s = q.front();
    q.pop();
    while (r[{s.first, s.second}]) {
      s.second++;
    }
    for (auto d : adj[s.first]) {
      if (s.second + d.second < tmm[d.first]) {
        tmm[d.first] = s.second + d.second;
        q.push({d.first, tmm[d.first]});
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    adj[a].push_back({b, c});
    adj[b].push_back({a, c});
  }
  for (int i = 1; i <= n; i++) {
    tmm[i] = 1e18;
  }
  for (int i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    while (x--) {
      long long f;
      cin >> f;
      tim[i].push_back(f);
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(tim[i].begin(), tim[i].end());
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < tim[i].size(); j++) {
      r[{i, tim[i][j]}] = 1;
    }
  }
  tmm[1] = 0;
  solve();
  cout << (tmm[n] == 1e18 ? -1 : tmm[n]) << endl;
  return 0;
}
