#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 17;
int N, M;
map<int, bool> m[maxn];
vector<pair<int, int> > graph[maxn];
long long DP[maxn];
priority_queue<pair<long long, int>, vector<pair<long long, int> >,
               greater<pair<long long, int> > >
    pq;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N >> M;
  for (int i = 1; i <= M; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    graph[x].push_back({y, z});
    graph[y].push_back({x, z});
  }
  for (int i = 1; i <= N; i++) {
    int x;
    cin >> x;
    while (x--) {
      int y;
      cin >> y;
      m[i][y] = true;
    }
  }
  memset(DP, 0x2F, sizeof DP);
  DP[1] = 0;
  pq.push({0, 1});
  while (!pq.empty()) {
    long long dx = pq.top().first;
    int u = pq.top().second;
    pq.pop();
    if (dx != DP[u]) continue;
    long long nx = dx;
    while (m[u].count(nx)) nx++;
    for (auto x : graph[u])
      if (nx + 1LL * x.second < DP[x.first])
        DP[x.first] = nx + 1LL * x.second, pq.push({DP[x.first], x.first});
  }
  long long ans = DP[N];
  if (ans >= 1LL << 50) ans = -1LL;
  cout << ans << endl;
  return 0;
}
