#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > e[100005];
map<pair<int, int>, int> mp;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    q;
int main() {
  cin >> n >> m;
  vector<int> dist(n, 2000000000);
  for (int i = 0; i < m; i++) {
    int a, b, w;
    cin >> a >> b >> w;
    a--;
    b--;
    e[a].push_back(pair<int, int>(b, w));
    e[b].push_back(pair<int, int>(a, w));
  }
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    vector<int> v;
    v.clear();
    for (int j = 0; j < t; j++) {
      int a;
      cin >> a;
      v.push_back(a);
    }
    int cnt;
    for (int j = 0; j < t; j++) {
      if (j == 0 or v[j] != v[j - 1] + 1) cnt = j;
      if (j == t - 1 or v[j] + 1 != v[j + 1])
        for (int k = cnt; k <= j; k++) mp[make_pair(i, v[k])] = v[j] - v[k] + 1;
    }
  }
  q.push(pair<int, int>(mp[make_pair(0, 0)], 0));
  dist[0] = 0;
  while (!q.empty()) {
    pair<int, int> p = q.top();
    q.pop();
    if (p.second == n - 1) break;
    for (int i = 0; i < e[p.second].size(); i++) {
      int x = e[p.second][i].first;
      int al = dist[p.second] + e[p.second][i].second +
               mp[make_pair(p.second, dist[p.second])];
      if (dist[x] > al) {
        dist[x] = al;
        q.push(pair<int, int>(dist[x], x));
      }
    }
  }
  if (dist[n - 1] == 2000000000)
    puts("-1");
  else
    printf("%d\n", dist[n - 1]);
  return 0;
}
