#include <bits/stdc++.h>
using namespace std;
vector<int> g[100000], w[100000];
set<int> t[100000];
long long d[100000];
int tt[100000];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int from, to, ww;
    cin >> from >> to >> ww;
    g[from - 1].push_back(to - 1);
    w[from - 1].push_back(ww);
    g[to - 1].push_back(from - 1);
    w[to - 1].push_back(ww);
  }
  for (int i = 0; i < n; i++) {
    int ki;
    cin >> ki;
    for (int j = 0; j < ki; j++) cin >> tt[j], t[i].insert(tt[j]);
  }
  priority_queue<pair<long long, int> > p;
  fill(d, d + n, INT_MAX);
  p.push(make_pair(0, 0));
  d[0] = 0;
  while (!p.empty()) {
    long long dc = abs(p.top().first);
    int v = p.top().second;
    p.pop();
    dc = min(d[v], dc);
    while (t[v].count(dc)) dc++;
    for (int i = 0; i < g[v].size(); i++) {
      int to = g[v][i];
      long long nt = dc + w[v][i];
      if (d[to] < nt) continue;
      d[to] = nt;
      p.push(make_pair(-nt, to));
    }
  }
  if (d[n - 1] == INT_MAX)
    cout << -1;
  else
    cout << d[n - 1];
  return 0;
}
