#include <bits/stdc++.h>
using namespace std;
const unsigned long long inf = 100000000000ll;
vector<vector<int> > adj, cst, wt;
unsigned long long dist[100000 + 1];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  adj.resize(n + 1);
  cst.resize(n + 1);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    adj[a].push_back(b);
    adj[b].push_back(a);
    cst[a].push_back(c);
    cst[b].push_back(c);
  }
  wt.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    int ww;
    scanf("%d", &ww);
    for (int j = 0; j < ww; j++) {
      int tt;
      scanf("%d", &tt);
      wt[i].push_back(tt);
    }
  }
  for (int i = 1; i <= n; i++) dist[i] = inf;
  dist[1] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      Q;
  Q.push(make_pair(0, 1));
  while (Q.empty() == false) {
    pair<int, int> p = Q.top();
    Q.pop();
    int ct = p.first, v = p.second;
    if (ct > dist[v]) continue;
    int l = wt[v].size();
    int id;
    if (l > 0) {
      id = lower_bound(wt[v].begin(), wt[v].end(), ct) - wt[v].begin();
      while (id < wt[v].size() && ct == wt[v][id]) ct++, id++;
    }
    for (int i = 0; i < adj[v].size(); i++) {
      int u = adj[v][i], ctt = cst[v][i];
      if ((ct + ctt) < dist[u]) {
        dist[u] = ct + ctt;
        Q.push(make_pair(dist[u], u));
      }
    }
  }
  if (dist[n] == inf)
    cout << "-1" << endl;
  else
    cout << dist[n] << endl;
  return 0;
}
