#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<pair<long long, long long> > v[100010];
vector<long long> tim[100010];
long long dist[100010];
void wait(long long& T, long long nod) {
  long long st = 0;
  long long en = (int)tim[nod].size() - 1;
  long long mid = 0;
  long long ans = -1;
  long long b = 0;
  while (st <= en) {
    mid = (st + en) / 2;
    if (tim[nod][mid] < T) {
      st = mid + 1;
    }
    if (tim[nod][mid] >= T) {
      en = mid - 1;
      ans = mid;
    }
  }
  if (ans == -1) return;
  while (1) {
    if (ans >= tim[nod].size()) break;
    if (T != tim[nod][ans]) break;
    T++;
    ans++;
  }
  return;
}
void dij() {
  priority_queue<pair<long long, long long> > pq;
  pq.push({0ll, 1});
  dist[1] = 0ll;
  while (!pq.empty()) {
    pair<long long, long long> fr = pq.top();
    pq.pop();
    long long nod = fr.second;
    long long T = fr.first * -1ll;
    if (T > dist[nod]) continue;
    wait(T, nod);
    for (long long i = 0; i < v[nod].size(); i++) {
      if ((T + v[nod][i].second) < dist[v[nod][i].first]) {
        pq.push({-1 * (T + v[nod][i].second), v[nod][i].first});
        dist[v[nod][i].first] = (T + v[nod][i].second);
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    v[a].push_back({b, c});
    v[b].push_back({a, c});
  }
  for (long long i = 1; i <= n; i++) {
    dist[i] = 1e18;
    long long x;
    cin >> x;
    for (long long l = 0; l < x; l++) {
      long long a;
      cin >> a;
      tim[i].push_back(a);
    }
  }
  dij();
  if (dist[n] == 1e18)
    cout << -1 << endl;
  else
    cout << dist[n] << endl;
  return 0;
}
