#include <bits/stdc++.h>
using namespace std;
FILE *in;
FILE *out;
struct State {
  int node, price;
  State(int node_ = 0, int price_ = 0) : node(node_), price(price_){};
  bool operator<(const State &r) const {
    return price != r.price ? price > r.price : node < r.node;
  }
};
int n, m;
vector<State> v[131072];
vector<int> times[131072];
priority_queue<State> q;
int vis[131072], best[131072];
int getPrice(int node, int atTime) {
  if (times[node].size() == 0) return atTime;
  int left, right, mid;
  left = 0, right = (int)times[node].size() - 1;
  int idx = (int)times[node].size();
  while (left <= right) {
    mid = (left + right) / 2;
    if (times[node][mid] < atTime)
      left = mid + 1;
    else {
      idx = mid;
      right = mid - 1;
    }
  }
  if (idx >= (int)times[node].size() || times[node][idx] > atTime)
    return atTime;
  left = idx, right = (int)times[node].size() - 1;
  while (left <= right) {
    mid = (left + right) / 2;
    if (times[node][mid] - times[node][idx] == mid - idx) {
      idx = mid;
      left = mid + 1;
    } else
      right = mid - 1;
  }
  return times[node][idx] + 1;
}
int dijkstra(int startNode, int endNode) {
  State cur, nxt;
  memset(vis, 0, sizeof(vis));
  memset(best, 127, sizeof(best));
  nxt.node = startNode;
  nxt.price = getPrice(startNode, 0);
  q.push(nxt);
  best[nxt.node] = nxt.price;
  while (!q.empty()) {
    cur = q.top();
    q.pop();
    if (vis[cur.node]) continue;
    vis[cur.node] = 1;
    if (cur.node == endNode) return cur.price;
    for (int i = 0; i < (int)v[cur.node].size(); i++) {
      nxt.node = v[cur.node][i].node;
      if (!vis[nxt.node]) {
        nxt.price = getPrice(nxt.node, cur.price + v[cur.node][i].price);
        if (nxt.price < best[nxt.node]) {
          best[nxt.node] = nxt.price;
          q.push(nxt);
        }
      }
    }
  }
  return -1;
}
int main(void) {
  in = stdin;
  out = stdout;
  fscanf(in, "%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int node1, node2, price;
    fscanf(in, "%d %d %d", &node1, &node2, &price);
    node1--;
    node2--;
    v[node1].push_back(State(node2, price));
    v[node2].push_back(State(node1, price));
  }
  for (int i = 0; i < n - 1; i++) {
    int k;
    fscanf(in, "%d", &k);
    for (int c = 0; c < k; c++) {
      int tmp;
      fscanf(in, "%d", &tmp);
      times[i].push_back(tmp);
    }
  }
  fprintf(out, "%d\n", dijkstra(0, n - 1));
  return 0;
}
