#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int>>> g;
vector<int> dist;
vector<bool> already;
vector<set<int>> oc;
int n, m, x, y, z, w, p;
class Compare {
 public:
  bool operator()(pair<int, int> &a, pair<int, int> &b) {
    return a.second > b.second;
  }
};
void dijkstra() {
  dist[1] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int>>, Compare> pq;
  pq.push({1, 0});
  while (!pq.empty()) {
    pair<int, int> u = pq.top();
    pq.pop();
    vector<pair<int, int>> e = g[u.first];
    if (already[u.first]) continue;
    while (oc[u.first].count(u.second)) {
      u.second += 1;
      continue;
    }
    for (auto j : e) {
      if ((u.second + j.second) < dist[j.first]) {
        dist[j.first] = u.second + j.second;
        pq.push({j.first, dist[j.first]});
      }
    }
    already[u.first] = true;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  scanf("%d%d", &n, &m);
  g.resize(n + 1);
  oc.resize(n + 1);
  already.assign(n + 1, false);
  dist.assign(n + 1, 0x3f3f3f3f);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &x, &y, &z);
    g[x].push_back({y, z});
    g[y].push_back({x, z});
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &w);
    for (int j = 0; j < w; ++j) {
      scanf("%d", &p);
      oc[i].insert(p);
    }
  }
  dijkstra();
  (dist[n] == 0x3f3f3f3f) ? printf("-1\n") : printf("%d\n", dist[n]);
  return 0;
}
