#include <bits/stdc++.h>
using namespace std;
void count() {}
vector<pair<int, int> > g[100001];
priority_queue<pair<int, int> > q;
map<int, bool> used[100001];
int d[100001];
int main() {
  count();
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    g[x].push_back(make_pair(y, z));
    g[y].push_back(make_pair(x, z));
  }
  for (int i = 1; i <= n; ++i) {
    d[i] = 2000000000;
    int k;
    scanf("%d", &k);
    for (int j = 1; j <= k; ++j) {
      int t;
      scanf("%d", &t);
      used[i][t] = true;
    }
  }
  q.push(make_pair(0, 1));
  while (!q.empty()) {
    int sum1 = -q.top().first;
    int from = q.top().second;
    q.pop();
    if (sum1 > d[from]) continue;
    int tsz = g[from].size();
    d[from] = sum1;
    while (used[from][sum1]) sum1++;
    for (int i = 0; i < tsz; ++i) {
      int to = g[from][i].first;
      int sum2 = g[from][i].second;
      int summ = sum2 + sum1;
      if (summ < d[to]) {
        d[to] = summ;
        q.push(make_pair(-d[to], to));
      }
    }
  }
  if (d[n] == 2000000000)
    puts("-1");
  else
    printf("%d\n", d[n]);
  return 0;
}
