#include <bits/stdc++.h>
using namespace std;
int n;
int m, d[100005];
multiset<int> timp[100005];
set<pair<int, int> > h;
vector<pair<int, int> > gf[100005];
void citeste() {
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int x, y, c;
    cin >> x >> y >> c;
    gf[x].push_back(make_pair(y, c));
    gf[y].push_back(make_pair(x, c));
  }
  for (int i = 1; i <= n; ++i) {
    int cate;
    cin >> cate;
    for (int j = 1; j <= cate; ++j) {
      int x;
      cin >> x;
      timp[i].insert(x);
    }
  }
}
void rezolva() {
  for (int i = 1; i <= n; ++i) d[i] = (1 << 30);
  h.insert(make_pair(0, 1));
  d[1] = 0;
  for (; h.size();) {
    int nod = (*h.begin()).second;
    int cost = (*h.begin()).first;
    h.erase(h.begin());
    for (; timp[nod].find(cost) != timp[nod].end();) ++cost;
    for (int j = 0; j < gf[nod].size(); ++j) {
      int vc = gf[nod][j].first;
      int c2 = gf[nod][j].second;
      if (d[vc] > c2 + cost) {
        d[vc] = c2 + cost;
        h.insert(make_pair(d[vc], vc));
      }
    }
  }
  if (d[n] != (1 << 30))
    cout << d[n] << "\n";
  else
    cout << -1 << "\n";
}
int main() {
  citeste();
  rezolva();
  return 0;
}
