#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
const double PI = acos(-1.0);
const int INF = 1e9;
const long long BIGINF = 4e18;
const long long MOD = 998244353;
const double EPS = 1e-6;
mt19937 rng(time(0));
uniform_int_distribution<int> uid(-1000000000, 1000000000);
vector<pair<int, int>> g[100009];
vector<int> v[100009];
int dx[100009], u[100009];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, a, b, c;
  cin >> n >> m;
  fill(dx, dx + n + 1, 2 * INF + 9);
  dx[0] = 0;
  while (m--) {
    cin >> a >> b >> c;
    --a, --b;
    g[a].push_back({b, c});
    g[b].push_back({a, c});
  }
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    v[i].resize(k);
    for (auto& j : v[i]) cin >> j;
  }
  v[n - 1].clear();
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      pq;
  pq.push({0, 0});
  while (pq.size()) {
    auto x = pq.top();
    pq.pop();
    if (!u[x.second]) {
      u[x.second] = 1;
      while (binary_search((v[x.second]).begin(), (v[x.second]).end(),
                           dx[x.second]))
        ++dx[x.second];
      x.first = dx[x.second];
      for (auto& i : g[x.second]) {
        if (x.first + i.second < dx[i.first]) {
          dx[i.first] = x.first + i.second;
          pq.push({dx[i.first], i.first});
        }
      }
    }
  }
  cout << (dx[n - 1] == 2 * INF + 9 ? -1 : dx[n - 1]) << '\n';
  return 0;
}
