#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
vector<pair<long long int, long long int> > v[100005];
vector<long long int> t[100005];
bool vis[100005];
long long int d[100005];
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int n, m, x, y, z;
  cin >> n >> m;
  for (long long int i = 0; i <= n + 1; i++) d[i] = 1e15;
  for (long long int i = 1; i <= m; i++) {
    cin >> x >> y >> z;
    v[x].push_back({y, z});
    v[y].push_back({x, z});
  }
  for (long long int i = 1; i <= n; i++) {
    cin >> y;
    for (long long int j = 1; j <= y; j++) {
      cin >> x;
      t[i].push_back(x);
    }
  }
  multiset<pair<long long int, long long int> > s;
  s.insert({0, 1});
  while (!s.empty()) {
    pair<long long int, long long int> p = *(s.begin());
    s.erase(s.begin());
    x = p.second;
    y = p.first;
    if (vis[x]) continue;
    vis[x] = 1;
    for (long long int i = 0; i <= (long long int)t[x].size() - 1; i++)
      if (t[x][i] == y) y++;
    for (auto i : v[x]) {
      if (y + i.second < d[i.first]) {
        d[i.first] = y + i.second;
        s.insert({d[i.first], i.first});
      }
    }
  }
  if (d[n] == 1e15) d[n] = -1;
  cout << d[n];
}
