#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PLI = pair<LL, int>;
const int N = 100005;
int h[N], e[N * 2], ne[N * 2], idx;
LL c[N];
LL dist[N];
LL w[N * 2];
set<LL> s[N];
bool st[N];
int n, m;
void add(int a, int b, LL c) {
  e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
LL dijkstra() {
  for (int i = 1; i <= n; ++i) dist[i] = 1e18;
  dist[1] = 0LL;
  priority_queue<PLI, vector<PLI>, greater<PLI> > heap;
  heap.push({0, 1});
  while (heap.size()) {
    auto t = heap.top();
    heap.pop();
    int ver = t.second;
    LL distance = t.first;
    if (st[ver]) continue;
    st[ver] = true;
    while (s[ver].find(dist[ver]) != s[ver].end() && ver != n) {
      ++dist[ver];
    }
    distance = dist[ver];
    for (int i = h[ver]; i != -1; i = ne[i]) {
      int j = e[i];
      if (dist[j] > distance + w[i]) {
        dist[j] = distance + w[i];
        heap.push({dist[j], j});
      }
    }
  }
  if (dist[n] == 1e18) return -1;
  return dist[n];
}
int main() {
  scanf("%d%d", &n, &m);
  memset(h, -1, sizeof h);
  int a, b, v;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%lld", &a, &b, &v);
    add(a, b, v), add(b, a, v);
  }
  int k;
  int t;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &k);
    for (int j = 1; j <= k; ++j) {
      scanf("%lld", &t);
      s[i].insert(t);
    }
  }
  LL res = dijkstra();
  printf("%lld\n", res);
  return 0;
}
