#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, long long int> > v[100010];
map<long long int, long long int> mp[100010];
long long int dis[100010], vis[100010];
int main() {
  ios::sync_with_stdio(false);
  long long int n, m, i, j, x, y, a, b, c, w;
  set<pair<long long int, long long int> > s;
  pair<long long int, long long int> p;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> a >> b >> c;
    v[a].push_back({b, c});
    v[b].push_back({a, c});
  }
  for (i = 1; i <= n; i++) {
    cin >> a;
    for (j = 0; j < a; j++) {
      cin >> x;
      mp[i][x] = 1;
    }
  }
  for (i = 1; i <= n; i++) dis[i] = 1e18;
  for (i = 0; i <= 1e18; i++) {
    if (mp[1].find(i) != mp[1].end()) {
    }
    s.insert({i, 1});
    dis[1] = i;
    break;
  }
  while (!s.empty()) {
    p = *s.begin();
    s.erase(s.begin());
    x = p.second;
    w = p.first;
    if (vis[x] == 1) continue;
    vis[x] = 1;
    if (x == n) break;
    for (i = w; i <= 1e18; i++) {
      if (mp[x].find(i) != mp[x].end()) {
        continue;
      }
      dis[x] = i;
      break;
    }
    w = i;
    for (i = 0; i < v[x].size(); i++) {
      y = v[x][i].first;
      if (dis[y] > w + v[x][i].second) {
        dis[y] = w + v[x][i].second;
        s.insert({dis[y], y});
      }
    }
  }
  if (dis[n] == 1e18)
    cout << -1 << endl;
  else
    cout << dis[n] << endl;
}
