#include <bits/stdc++.h>
using namespace std;
struct node {
  long long u, cst;
  node(long long _u, long long _cst) {
    u = _u;
    cst = _cst;
  }
};
bool operator<(node A, node B) { return A.cst > B.cst; }
long long inf = 9999999999999997, dist[100002];
map<int, map<int, int> > mp, nq;
vector<long long> adj[100002], cost[100002], vct[100002];
void dijkstra(long long n, long long src) {
  long long i, vsz, y, p, q;
  vector<long long>::iterator it;
  priority_queue<node> pq;
  y = mp[src][0];
  dist[src] = y;
  pq.push(node(src, y));
  while (!pq.empty()) {
    node x = pq.top();
    pq.pop();
    long long nu = x.u;
    vsz = adj[nu].size();
    for (i = 0; i < vsz; i++) {
      long long v = adj[nu][i];
      if (dist[nu] + cost[nu][i] < dist[v]) {
        dist[v] = dist[nu] + cost[nu][i];
        q = dist[v];
        if (mp[v][q] != 0 && v != n) {
          dist[v] = mp[v][q];
        }
        if (nq[v][dist[v]] == 0) {
          pq.push(node(v, dist[v]));
          nq[v][dist[v]] = 1;
        }
      }
    }
  }
}
int main() {
  long long n, m, w, a, b, i, j, k, prv, d;
  scanf("%lld %lld", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%lld %lld %lld", &a, &b, &w);
    adj[a].push_back(b);
    adj[b].push_back(a);
    cost[a].push_back(w);
    cost[b].push_back(w);
  }
  for (i = 1; i <= n; i++) {
    dist[i] = inf;
    scanf("%lld", &k);
    for (j = 1; j <= k; j++) {
      scanf("%lld", &a);
      vct[i].push_back(a);
    }
    if (k > 0) {
      d = a + 1;
      for (j = k - 1; j >= 0; j--) {
        a = vct[i][j];
        if (j == k - 1) {
          mp[i][a] = d;
        } else {
          b = vct[i][j + 1];
          if (a + 1 != b) {
            d = a + 1;
          }
          mp[i][a] = d;
        }
      }
    }
  }
  dijkstra(n, 1);
  if (dist[n] == inf)
    printf("-1\n");
  else {
    printf("%lld\n", dist[n]);
  }
  return 0;
}
