#include <bits/stdc++.h>
using namespace std;
map<int, int> mp[100005];
const int MAXN = 100005;
const int inf = 2000001000;
const int MAXNN = 200005;
struct Node {
  int v;
  int cost;
  int next;
} node[MAXNN];
int adj[MAXN];
int d[MAXN];
int n, size;
struct comp {
  bool operator()(int a, int b) { return d[a] > d[b]; }
};
void addedge(int u, int v, int w) {
  node[size].v = v;
  node[size].cost = w;
  node[size].next = adj[u];
  adj[u] = size++;
}
priority_queue<int, vector<int>, comp> Q;
void Dij(int s) {
  int x, v, u;
  Q.push(s);
  d[s] = 0;
  while (mp[s][d[s]] != 0) d[s] += mp[s][d[s]];
  while (!Q.empty()) {
    u = Q.top();
    Q.pop();
    for (int i = adj[u]; i != -1; i = node[i].next) {
      x = d[u] + node[i].cost;
      v = node[i].v;
      if (d[v] > x) {
        if (v != n)
          while (mp[v][x] != 0) x += mp[v][x];
        if (d[v] > x) {
          d[v] = x;
          Q.push(v);
        }
      }
    }
  }
}
int main() {
  int m, u, v, w, temp, tt[100005];
  scanf("%d %d", &n, &m);
  for (int i = 0; i <= n; i++) mp[i].clear();
  for (int i = 0; i <= n; i++) {
    adj[i] = -1;
    d[i] = inf;
  }
  size = 0;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    addedge(u, v, w);
    addedge(v, u, w);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &temp);
    for (int j = 1; j <= temp; j++) {
      scanf("%d", &tt[j]);
    }
    for (int j = temp; j >= 1; j--) mp[i][tt[j]] = mp[i][tt[j] + 1] + 1;
  }
  Dij(1);
  if (d[n] != inf) {
    printf("%d\n", d[n]);
  } else
    puts("-1");
  return 0;
}
