#include <bits/stdc++.h>
using namespace std;
vector<int> block[100005];
vector<pair<int, int> > graph[100005];
int vis[100005];
int cango(int ver, int now) {
  vector<int>::iterator it;
  it = lower_bound(block[ver].begin(), block[ver].end(), now);
  while (it != block[ver].end()) {
    if (now != *it) return now;
    now++;
    *it++;
  }
  return now;
}
int dijkstra(int n) {
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      Q;
  Q.push(make_pair(0, 0));
  int i;
  while (!Q.empty()) {
    pair<int, int> now = Q.top();
    Q.pop();
    if (vis[now.second]) continue;
    vis[now.second] = 1;
    if (now.second == n - 1) return now.first;
    int st = cango(now.second, now.first);
    for (i = 0; i < graph[now.second].size(); i++)
      Q.push(make_pair(st + graph[now.second][i].second,
                       graph[now.second][i].first));
  }
  return -1;
}
int main() {
  int n, m, i;
  scanf("%d", &n);
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d", &u);
    scanf("%d", &v);
    scanf("%d", &w);
    u--;
    v--;
    graph[u].push_back(make_pair(v, w));
    graph[v].push_back(make_pair(u, w));
  }
  for (i = 0; i < n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      int x;
      scanf("%d", &x);
      block[i].push_back(x);
    }
  }
  printf("%d\n", dijkstra(n));
  return 0;
}
