#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int inf = 1000222333;
int n, m, u, v, c, k;
priority_queue<pair<int, int> > Q;
vector<int> t[N];
vector<pair<int, int> > adj[N];
int tt[N];
bool popped[N];
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &u, &v, &c);
    adj[u].push_back(make_pair(v, c));
    adj[v].push_back(make_pair(u, c));
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      scanf("%d", &u);
      t[i].push_back(u);
    }
  }
  for (int i = 2; i <= n; i++) tt[i] = inf;
  if (t[1].size() > 0 && t[1][0] == 0) {
    k = 1;
    while (k <= t[1].size() - 1 && t[1][k] == t[1][k - 1] + 1) k++;
    tt[1] = k;
  }
  Q.push(make_pair(-tt[1], 1));
  while (!Q.empty()) {
    u = Q.top().second;
    c = -Q.top().first;
    Q.pop();
    if (u == n) {
      cout << c << endl;
      return 0;
    }
    if (popped[u] && c > tt[u]) continue;
    popped[u] = true;
    for (int i = 0; i < t[u].size(); i++)
      if (t[u][i] == c) {
        k = i + 1;
        while (k < t[u].size() && t[u][k] == t[u][k - 1] + 1) k++;
        c += k - i;
      }
    for (int i = 0; i < adj[u].size(); i++) {
      v = adj[u][i].first;
      if (!popped[v] && c + adj[u][i].second < tt[v]) {
        tt[v] = c + adj[u][i].second;
        Q.push(make_pair(-tt[v], v));
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
