#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int v;
  int w;
  Edge* next;
  void add(int v, int w, Edge*& head) {
    this->v = v;
    this->w = w;
    this->next = head;
    head = this;
  }
} edges[200100];
Edge* h[100100];
struct Q {
  int v;
  int t;
  bool operator<(const Q& q) const { return v < q.v || v == q.v && t < q.t; }
  void init(int v, int t) {
    this->v = v;
    this->t = t;
  }
} q[100100], q0;
void addEdge(int v1, int v2, int w) {
  static Edge* e = edges;
  (e++)->add(v2, w, h[v1]);
  (e++)->add(v1, w, h[v2]);
}
int d[100010];
struct CMP {
  bool operator()(int a, int b) const {
    return d[a] < d[b] || d[a] == d[b] && a < b;
  }
};
set<int, CMP> heap;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int v1, v2, w;
    scanf("%d %d %d", &v1, &v2, &w);
    v1--, v2--;
    addEdge(v1, v2, w);
  }
  int u = 0;
  for (int i = 0; i < n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      int t;
      scanf("%d", &t);
      q[u++].init(i, t);
    }
  }
  memset(d, 127, sizeof(d));
  d[0] = 0;
  heap.insert(0);
  while (!heap.empty()) {
    int v = *heap.begin();
    heap.erase(heap.begin());
    if (v == n - 1) {
      printf("%d\n", d[v]);
      return 0;
    }
    int dist = d[v];
    q0.init(v, dist);
    Q* qi = lower_bound(q, q + u, q0);
    while (qi < q + u && qi->v == v && qi->t == dist) {
      dist++;
      qi++;
    }
    for (Edge* e = h[v]; e; e = e->next) {
      if (d[e->v] > dist + e->w) {
        heap.erase(e->v);
        d[e->v] = dist + e->w;
        heap.insert(e->v);
      }
    }
  }
  printf("-1\n");
  return 0;
}
