#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30) - 1;
int n, m, nes = 0, s[200005], e[200005], h[200005], c[200005], d[200005],
          t[200005], ts[200005];
struct heap {
  int size, a[200005], pos[200005];
  inline void Adj_down(int w) {
    int x = a[w], targ = w << 1, xKey = d[a[w]];
    for (; targ <= size; targ = w << 1) {
      if ((targ < size) && (d[a[targ + 1]] < d[a[targ]])) ++targ;
      if (d[a[targ]] < xKey) {
        a[w] = a[targ], pos[a[w]] = w;
        w = targ;
      } else
        break;
    }
    a[w] = x, pos[x] = w;
  }
  inline void Adj_up(int w) {
    int x = a[w], xKey = d[a[w]];
    for (; (w > 1) && (d[a[w >> 1]] > xKey); w >>= 1)
      a[w] = a[w >> 1], pos[a[w]] = w;
    a[w] = x, pos[x] = w;
  }
  inline void build() {
    size = n;
    for (int i = 1; i <= size; ++i) a[i] = i, pos[i] = i;
  }
  inline void pop() {
    a[1] = a[size--];
    pos[a[1]] = 1, Adj_down(1);
  }
} H;
inline int d2f(int s, int e, int x) {
  int mid;
  while (s <= e) {
    mid = (s + e) >> 1;
    if (t[mid] == x)
      return mid;
    else if (t[mid] < x)
      s = mid + 1;
    else
      e = mid - 1;
  }
  return 0;
}
inline int AT(int x, int T) {
  int w = d2f(ts[x], ts[x + 1] - 1, T);
  for (; w < ts[x + 1] && t[w] == T; ++T, ++w)
    ;
  return T;
}
int main() {
  scanf("%d%d", &n, &m);
  int x, y, z, k;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &x, &y, &z);
    ++nes, e[nes] = y, h[nes] = s[x], s[x] = nes, c[nes] = z;
    ++nes, e[nes] = x, h[nes] = s[y], s[y] = nes, c[nes] = z;
  }
  ts[1] = 1, t[0] = -1;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &k);
    for (int j = 0; j < k; ++j) scanf("%d", &t[ts[i] + j]);
    ts[i + 1] = ts[i] + k;
  }
  ts[n + 1] = ts[n];
  for (int i = 2; i <= n; ++i) d[i] = inf;
  d[1] = 0;
  H.build();
  while (H.size && d[H.a[1]] < inf) {
    x = H.a[1];
    d[x] = AT(x, d[x]);
    for (int w = s[x]; w; w = h[w])
      if (d[x] + c[w] < d[e[w]]) {
        d[e[w]] = d[x] + c[w];
        H.Adj_up(H.pos[e[w]]);
      }
    H.pop();
  }
  if (d[n] < inf)
    printf("%d\n", d[n]);
  else
    printf("-1\n");
  return 0;
}
