#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 0, -1, 1, 1, -1, -1, 1};
const int dy[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1000000007;
const int N = 1e5 + 50;
int n, m, k, t;
vector<pair<int, int> > adj[N];
vector<int> times[N];
int sp[N];
int getNext(int node, int st) {
  int idx = -1;
  for (int i = 0; i < times[node].size(); ++i)
    if (times[node][i] == st) {
      idx = i;
      break;
    }
  if (idx == -1) return 0;
  for (; idx < times[node].size() - 1; ++idx)
    if (times[node][idx + 1] - times[node][idx] > 1)
      return times[node][idx] - st + 1;
  return times[node][idx] - st + 1;
}
int main() {
  cin >> n >> m;
  int u, v, c;
  for (int i = 0; i < m; ++i) {
    cin >> u >> v >> c;
    u--, v--;
    adj[u].push_back({v, c});
    adj[v].push_back({u, c});
  }
  for (int i = 0; i < n; ++i) {
    cin >> k;
    while (k--) {
      cin >> t;
      times[i].push_back(t);
    }
  }
  for (int i = 0; i < n; ++i) sp[i] = (1200000000);
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      pq;
  pq.push({0, 0});
  sp[0] = 0;
  while (!pq.empty()) {
    u = pq.top().second;
    c = pq.top().first;
    pq.pop();
    if (u == n - 1) break;
    if (sp[u] < c) continue;
    int extra = getNext(u, c);
    for (auto edge : adj[u]) {
      int to = edge.first;
      int cost = edge.second;
      if (c + cost + extra < sp[to]) {
        sp[to] = c + cost + extra;
        pq.push({sp[to], to});
      }
    }
  }
  cout << (sp[n - 1] != (1200000000) ? sp[n - 1] : -1) << endl;
  return 0;
}
