#include <bits/stdc++.h>
using namespace std;
const int maxn = 100007, maxm = 200007, inf = 0x3f3f3f3f;
int n, m, s;
int cnt = 0;
int head[maxn], dis[maxn], num[maxn];
bool vis[maxn];
map<int, bool> h[maxn];
struct edge {
  int next, to, val;
} e[maxm];
void addEdge(int from, int to, int val) {
  e[++cnt].next = head[from];
  e[cnt].val = val;
  e[cnt].to = to;
  head[from] = cnt;
}
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 1) + (s << 3) + ch - '0', ch = getchar();
  return s * w;
}
void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
  return;
}
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    pq;
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) dis[i] = inf;
  dis[1] = 0;
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read(), val = read();
    addEdge(x, y, val);
    addEdge(y, x, val);
  }
  for (int i = 1; i <= n; i++) {
    int k = read();
    for (int j = 1; j <= k; j++) {
      int r = read();
      h[i][r] = true;
    }
  }
  while (!pq.empty()) pq.pop();
  pq.push(make_pair(0, 1));
  while (!pq.empty()) {
    pair<int, int> top = pq.top();
    pq.pop();
    int u = top.second, d = top.first;
    if (vis[u] || dis[u] != d) continue;
    vis[u] = true;
    while (h[u][d] && u != n) d++;
    dis[u] = d;
    for (int i = head[u]; i; i = e[i].next) {
      int v = e[i].to;
      int rtd = e[i].val + dis[u];
      if (rtd < dis[v]) dis[v] = rtd, pq.push(make_pair(rtd, v));
    }
  }
  if (dis[n] == inf) dis[n] = -1;
  printf("%d\n", dis[n]);
  return 0;
}
