#include <bits/stdc++.h>
const int INF = (int)(1e9);
const long long INFLL = (long long)(1e18);
const double EPS = 1e-13;
using namespace std;
const int maxn = 100010;
int n, m;
vector<pair<int, int> > G[maxn];
vector<vector<int> > travellers;
bool visited[maxn];
long long dist[maxn];
long long find_wait(int to, long long time) {
  int pos =
      int(lower_bound((travellers[to]).begin(), (travellers[to]).end(), time) -
          travellers[to].begin());
  for (int i = pos; i < (int)travellers[to].size(); i++) {
    if (travellers[to][i] != time) {
      return time;
    }
    time++;
  }
  return time;
}
long long dijkstra() {
  memset(dist, 0x3f, sizeof(dist));
  memset(visited, false, sizeof(visited));
  priority_queue<pair<long long, int> > Q;
  Q.push(make_pair(0, 1));
  dist[1] = 0;
  while (!Q.empty()) {
    long long time = -Q.top().first;
    int u = Q.top().second;
    Q.pop();
    if (u == n) return time;
    if (visited[u]) continue;
    visited[u] = true;
    long long wait = find_wait(u, time);
    for (int j = 0; j < (int)G[u].size(); j++) {
      pair<int, int> v = G[u][j];
      long long new_time = wait + v.second;
      if (new_time < dist[v.first]) {
        dist[u] = new_time;
        Q.push(make_pair(-new_time, v.first));
      }
    }
  }
  return -1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    G[a].push_back(make_pair(b, c));
    G[b].push_back(make_pair(a, c));
  }
  travellers.resize(n + 1);
  for (int i = 1; i < n; i++) {
    int ki;
    cin >> ki;
    for (int j = 0; j < ki; j++) {
      int x;
      cin >> x;
      travellers[i].push_back(x);
    }
  }
  long long ans = dijkstra();
  cout << ans << endl;
}
