#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e18;
const int N = 1e5 + 2;
const long long mod = 1e9 + 7;
const long long p = 31;
int n, m;
vector<pair<long long, long long>> adj[N];
map<pair<int, long long>, int> mp;
bool vis[N];
long long dik(int x, int y) {
  priority_queue<pair<long long, long long>> qe;
  long long ret = oo;
  qe.push({0, x});
  while (qe.size()) {
    long long cost = qe.top().first * -1;
    int node = qe.top().second;
    if (node == y) ret = min(ret, cost);
    cost += mp[{node, cost}];
    if (vis[node]) {
      qe.pop();
      continue;
    }
    qe.pop();
    vis[node] = 1;
    for (auto j : adj[node]) {
      qe.push({-1 * (j.second + cost), j.first});
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  while (m--) {
    int x, y, z;
    cin >> x >> y >> z;
    adj[x].push_back({y, z});
    adj[y].push_back({x, z});
  }
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    int a[k + 5];
    memset(a, 0, sizeof a);
    for (int i = 0; i < k; i++) cin >> a[i];
    ;
    for (int j = k - 1; j > -1; j--) {
      mp[{i, a[j]}] = 1 + mp[{i, a[j] + 1}];
    }
  }
  long long ans = dik(1, n);
  if (ans == oo) ans = -1;
  cout << ans;
  return 0;
}
