#include <bits/stdc++.h>
using namespace std;
int n, m, mark[100010], dist[100010];
vector<pair<int, int> > to[100010];
deque<int> q;
set<int> ban[100010];
int main() {
  register int i, j, k;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    to[a].push_back(pair<int, int>(b, c));
    to[b].push_back(pair<int, int>(a, c));
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &j);
    while (j--) {
      scanf("%d", &k);
      ban[i].insert(k);
    }
  }
  memset(dist, 0x7f, sizeof(dist));
  dist[1] = 0, mark[1] = 1;
  q.push_back(1);
  while (q.size()) {
    int cur = q.front();
    long long dist_cur = dist[cur];
    if (ban[cur].find(dist_cur) != ban[cur].end())
      for (; ban[cur].find(dist_cur) != ban[cur].end(); dist_cur++)
        ;
    for (i = 0; i < to[cur].size(); i++) {
      j = to[cur][i].first;
      k = to[cur][i].second;
      if (dist[j] > dist_cur + k) {
        dist[j] = dist_cur + k;
        if (!mark[j]++) q.push_back(j);
      }
    }
    mark[cur] = 0;
    q.pop_front();
  }
  printf("%d\n", dist[n] == 0x7f7f7f7f ? -1 : dist[n]);
  return 0;
}
