#include <bits/stdc++.h>
using namespace std;
long long n, m, a, b, c;
const long long INF = 1e18;
vector<long long> dist;
set<pair<long long, long long>> q;
vector<vector<pair<long long, long long>>> g;
vector<vector<long long>> t;
void dijkstra_set(long long start) {
  dist.resize(n, INF);
  dist[start] = 0;
  q.insert({0, start});
  while (!q.empty()) {
    long long u = q.begin()->second;
    q.erase(q.begin());
    for (pair<long long, long long> x : g[u]) {
      long long v = x.first, wt = x.second;
      long long d;
      int l = 0, r = t[u].size() - 1;
      while (l + 1 != r) {
        int M = (l + r) / 2;
        if (t[u][M] <= dist[u]) {
          l = M;
        } else {
          r = M;
        }
      }
      if (t[u][l] < dist[u]) {
        d = dist[u];
      } else {
        int L = l, R = t[u].size() - 1;
        while (L + 1 != R) {
          int M = (L + R) / 2;
          if (t[u][M] - t[u][l] == M - l) {
            L = M;
          } else {
            R = M;
          }
        }
        d = t[u][L] + 1;
      }
      if (d + wt < dist[v]) {
        q.erase({dist[v], v});
        dist[v] = d + wt;
        q.insert({dist[v], v});
      }
    }
  }
}
int main() {
  cin >> n >> m;
  g.resize(n);
  t.resize(n);
  for (int j = 0; j < m; ++j) {
    cin >> a >> b >> c;
    g[a - 1].push_back({b - 1, c});
    g[b - 1].push_back({a - 1, c});
  }
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    t[i].resize(k + 2);
    t[i].front() = -1;
    for (int j = 1; j <= k; ++j) {
      cin >> t[i][j];
    }
    t[i].back() = INF;
  }
  dijkstra_set(0);
  if (dist[n - 1] == INF) {
    cout << -1 << endl;
    return 0;
  }
  cout << dist[n - 1] << endl;
  return 0;
}
