#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 10;
int head[M], cnt;
struct Edge {
  int u, v, c, next;
  void set(int _u, int _v, int _c) {
    u = _u, v = _v, c = _c;
    next = head[u];
    head[u] = cnt++;
  }
} edge[M << 1];
int dis[M], n, m;
queue<int> q;
vector<int> g[M];
int serach(int t, int u) {
  int res = 0;
  int b = lower_bound(g[u].begin(), g[u].end(), t) - g[u].begin();
  if (b == g[u].size()) return res;
  if (g[u][b] == t) {
    res += serach(t + 1, u) + 1;
  }
  return res;
}
void bfs() {
  memset(dis, -1, sizeof(dis));
  dis[1] = 0;
  q.push(1);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    int t = dis[u] + serach(dis[u], u);
    for (int i = head[u]; i != -1; i = edge[i].next) {
      int v = edge[i].v, c = edge[i].c;
      if (dis[v] == -1 || dis[v] > t + c) {
        dis[v] = t + c;
        q.push(v);
      }
    }
  }
}
int main() {
  cnt = 0;
  memset(head, -1, sizeof(head));
  cin >> n >> m;
  while (m--) {
    int u, v, c;
    cin >> u >> v >> c;
    edge[cnt].set(u, v, c);
    edge[cnt].set(v, u, c);
  }
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    while (k--) {
      int v;
      cin >> v;
      g[i].push_back(v);
    }
  }
  bfs();
  cout << dis[n] << endl;
  return 0;
}
