#include <bits/stdc++.h>
std::vector<std::vector<std::pair<int, int> > > adjlist;
std::vector<std::vector<int> > bad;
std::vector<std::vector<int> > nm;
std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >,
                    std::greater<std::pair<int, int> > >
    pq;
int mdist[100005] = {};
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  int v, e, a_tm, b_tm, w_tm, rrr, foxy;
  std::cin >> v >> e;
  adjlist.resize(v + 5);
  bad.resize(v + 5);
  nm.resize(v + 5);
  for (int i = 0; i < e; i++) {
    std::cin >> a_tm >> b_tm >> w_tm;
    a_tm--;
    b_tm--;
    adjlist[a_tm].push_back(std::make_pair(b_tm, w_tm));
    adjlist[b_tm].push_back(std::make_pair(a_tm, w_tm));
  }
  for (int i = 0; i < v; i++) {
    std::cin >> rrr;
    while (rrr--) {
      std::cin >> foxy;
      bad[i].push_back(foxy);
    }
    if (bad[i].size()) {
      nm[i].resize(bad[i].size());
      nm[i][bad[i].size() - 1] = 1;
      for (int j = bad[i].size() - 2; j >= 0; j--) {
        if (bad[i][j] + 1 == bad[i][j + 1])
          nm[i][j] = nm[i][j + 1] + 1;
        else
          nm[i][j] = 1;
      }
    }
  }
  for (int i = 0; i < v; i++) mdist[i] = 2000000000;
  for (int i = 0;; i++) {
    if (std::binary_search(bad[0].begin(), bad[0].end(), i)) continue;
    pq.push(std::make_pair(i, 0));
    break;
  }
  while (!pq.empty()) {
    int w = pq.top().first;
    int s = pq.top().second;
    pq.pop();
    if (w < mdist[s]) {
      mdist[s] = w;
      if (std::binary_search(bad[s].begin(), bad[s].end(), w)) {
        int yop = nm[s][std::distance(
            bad[s].begin(), std::lower_bound(bad[s].begin(), bad[s].end(), w))];
        for (std::vector<std::pair<int, int> >::iterator it =
                 adjlist[s].begin();
             it != adjlist[s].end(); it++)
          pq.push(std::make_pair(w + (it->second) + yop, it->first));
      } else {
        for (std::vector<std::pair<int, int> >::iterator it =
                 adjlist[s].begin();
             it != adjlist[s].end(); it++)
          pq.push(std::make_pair(w + (it->second), it->first));
      }
    }
  }
  std::cout << (mdist[v - 1] == 2000000000 ? -1 : mdist[v - 1]) << '\n';
}
