#include <bits/stdc++.h>
using namespace std;
vector<unsigned long long> timer[100000 + 100], coun[100000 + 100];
unsigned long long n, m, dist[100000 + 100];
vector<pair<unsigned long long, unsigned long long> > graph[100000 + 100];
const unsigned long long inf = 1ll << 50;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  while (m--) {
    int u, v, c;
    cin >> u >> v >> c;
    u--;
    v--;
    graph[u].push_back({v, c});
    graph[v].push_back({u, c});
  }
  for (int i = 0; i < n; i++) {
    cin >> m;
    for (int j = 0; j < m; j++) {
      unsigned long long tmp;
      cin >> tmp;
      timer[i].push_back(tmp);
      coun[i].push_back(1);
    }
    for (int j = m - 2; j >= 0; j--)
      if (timer[i][j] + 1 == timer[i][j + 1]) coun[i][j] = coun[i][j + 1] + 1;
  }
  for (int i = 0; i < n + 10; i++) dist[i] = inf;
  priority_queue<pair<unsigned long long, unsigned long long>,
                 vector<pair<unsigned long long, unsigned long long> >,
                 greater<pair<unsigned long long, unsigned long long> > >
      pq;
  int tmp = (timer[0].empty() || timer[0][0] != 0) ? 0 : coun[0][0];
  dist[0] = tmp;
  pq.push(pair<unsigned long long, unsigned long long>(tmp, 0));
  while (!pq.empty()) {
    pair<unsigned long long, unsigned long long> act = pq.top();
    pq.pop();
    unsigned long long d = act.first, u = act.second;
    if (d > dist[u]) continue;
    for (auto &v : graph[u]) {
      unsigned long long tmp1 = dist[u] + v.second;
      unsigned long long tmp2 = 0;
      auto l =
          lower_bound((timer[v.first]).begin(), (timer[v.first]).end(), tmp1);
      int idx = (l - timer[v.first].begin());
      if (v.first != n - 1 && !timer[v.first].empty() &&
          timer[v.first][idx] == tmp1)
        tmp2 = coun[v.first][idx];
      if (tmp1 + tmp2 < dist[v.first]) {
        dist[v.first] = tmp1 + tmp2;
        pq.push(pair<unsigned long long, unsigned long long>(dist[v.first],
                                                             v.first));
      }
    }
  }
  unsigned long long res = dist[n - 1];
  if (res == inf)
    cout << "-1\n";
  else
    cout << res << "\n";
  return 0;
}
