#include <bits/stdc++.h>
using namespace std;
unsigned long long int MOD = 1000000007;
unsigned long long int B = 13331;
bool cmp(const int &a, const int &b) { return a < b; }
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
vector<pair<int, int> > edges[100005];
vector<int> times[100005];
int dist[100005];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int i, j, k;
  for (i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    edges[a - 1].push_back(make_pair(b - 1, c));
    edges[b - 1].push_back(make_pair(a - 1, c));
  }
  for (i = 0; i < n; i++) {
    int k;
    scanf("%d", &k);
    times[i].resize(k);
    for (j = 0; j < k; j++) scanf("%d", &times[i][j]);
  }
  for (i = 1; i < n; i++) dist[i] = 2 * MOD;
  set<pair<int, int> > q;
  dist[0] = 0;
  q.insert(make_pair(dist[0], 0));
  while (!q.empty()) {
    int v = q.begin()->second;
    q.erase(q.begin());
    if (v == n - 1) break;
    int xx = times[v].size();
    for (i = 0; i < xx; i++)
      if (dist[v] == times[v][i]) dist[v]++;
    int x = edges[v].size();
    for (i = 0; i < x; i++) {
      int to = edges[v][i].first;
      int wt = edges[v][i].second;
      if (dist[v] + wt < dist[to]) {
        q.erase(make_pair(dist[to], to));
        dist[to] = dist[v] + wt;
        q.insert(make_pair(dist[to], to));
      }
    }
  }
  if (dist[n - 1] == 2 * MOD)
    printf("-1");
  else
    printf("%d", dist[n - 1]);
  return 0;
}
