#include <bits/stdc++.h>
using namespace std;
struct data {
  int to, len;
  data(int _to, int _len) {
    to = _to;
    len = _len;
  }
  friend bool operator<(const data &a, const data &b) { return a.len > b.len; }
};
int n, m;
bool mark[100003];
set<int> s[100003];
vector<data> adj[100003];
priority_queue<data> heap;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0, x, y, z; i < m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    adj[x].push_back(data(y, z));
    adj[y].push_back(data(x, z));
  }
  for (int i = 1, x, y; i <= n; i++) {
    scanf("%d", &x);
    for (int j = 0; j < x; j++) {
      scanf("%d", &y);
      s[i].insert(y);
    }
  }
  heap.push(data(1, 0));
  while (!heap.empty()) {
    data tmp = heap.top();
    heap.pop();
    if (tmp.to == n) {
      printf("%d\n", tmp.len);
      exit(0);
    }
    if (mark[tmp.to]) continue;
    mark[tmp.to] = true;
    while (s[tmp.to].count(tmp.len)) tmp.len++;
    for (int i = 0; i < (int)adj[tmp.to].size(); i++)
      if (!mark[adj[tmp.to][i].to])
        heap.push(data(adj[tmp.to][i].to, tmp.len + adj[tmp.to][i].len));
  }
  printf("-1\n");
  return 0;
}
