#include <bits/stdc++.h>
using namespace std;
std::vector<pair<int, int>> adj[100009];
vector<int> wt[100009];
int status[100009];
int ans[100009];
int vis[100009];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    adj[x].push_back({y, z});
    adj[y].push_back({x, z});
  }
  for (int i = 0; i < n; i++) {
    int l = 0;
    cin >> l;
    for (int k = 0; k < l; k++) {
      int x;
      cin >> x;
      wt[i + 1].push_back(x);
    }
  }
  memset(ans, 0x3f, sizeof ans);
  priority_queue<pair<int, int>> pq;
  pq.push({0, 1});
  while (!pq.empty()) {
    auto it = pq.top();
    pq.pop();
    if (vis[it.second]) continue;
    vis[it.second] = 1;
    int idx =
        lower_bound(wt[it.second].begin(), wt[it.second].end(), -it.first) -
        wt[it.second].begin();
    int ct = 0;
    if (idx >= 0 and idx < wt[it.second].size() and
        wt[it.second][idx] == -it.first) {
      int lt = -it.first - 1;
      while (idx < wt[it.second].size() and wt[it.second][idx] == lt + 1) {
        ct++;
        lt++;
        idx++;
      }
    }
    for (auto i : adj[it.second]) {
      int v = i.first;
      int z = i.second;
      int extra = ct;
      if (ans[v] > -it.first + extra + z) {
        ans[v] = -it.first + extra + z;
        pq.push({-ans[v], v});
      }
    }
  }
  cout << ((ans[n] >= ans[0]) ? -1 : ans[n]) << endl;
  return 0;
}
