#include <bits/stdc++.h>
using namespace std;
struct E {
  int v, w, next;
} e[200010];
int head[200010], cnt;
int dis[200010], vis[200010];
int tmp[200010];
map<int, int> Map[200010];
void add(int u, int v, int w) {
  e[cnt].v = v;
  e[cnt].w = w;
  e[cnt].next = head[u];
  head[u] = cnt++;
}
queue<int> q;
void spfa(int s, int t) {
  int i, u, v, D;
  for (i = 1; i <= t; ++i) {
    dis[i] = -1;
    vis[i] = 0;
  }
  dis[s] = 0;
  while (!q.empty()) q.pop();
  q.push(s);
  vis[s] = 1;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    vis[u] = 0;
    for (i = head[u]; ~i; i = e[i].next) {
      v = e[i].v;
      if (dis[v] == -1 || dis[v] > dis[u] + Map[u][dis[u]] + e[i].w) {
        dis[v] = dis[u] + Map[u][dis[u]] + e[i].w;
        if (vis[v] == 0) {
          q.push(v);
          vis[v] = 1;
        }
      }
    }
  }
}
int main() {
  int n, m, k, a, b, c;
  while (scanf("%d%d", &n, &m) == 2) {
    memset(head, -1, sizeof(head));
    cnt = 0;
    while (m--) {
      scanf("%d%d%d", &a, &b, &c);
      add(a, b, c);
      add(b, a, c);
    }
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &k);
      if (k == 0) continue;
      for (int j = 0; j < k; ++j) scanf("%d", &tmp[j]);
      if (i == n) break;
      Map[i][tmp[k - 1]] = 1;
      for (int j = k - 2; j >= 0; --j) {
        if (tmp[j] + 1 == tmp[j + 1])
          Map[i][tmp[j]] = Map[i][tmp[j + 1]] + 1;
        else
          Map[i][tmp[j]] = 1;
      }
    }
    spfa(1, n);
    printf("%d\n", dis[n]);
  }
}
