#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > vec(100001);
unsigned long long int INF = INT_MAX;
bool chek(int v, int l, int r, int val) {
  if (r >= l) {
    int mid = (l + r) / 2;
    if (vec[v][mid] == val) return true;
    if (vec[v][mid] > val)
      return chek(v, l, mid - 1, val);
    else
      return chek(v, mid + 1, r, val);
  }
  return false;
}
int main() {
  int n, m, s;
  scanf("%d%d", &n, &m);
  vector<vector<pair<int, int> > > g(n + 1);
  vector<int> d(n + 1, INF);
  set<pair<int, int> > q;
  for (int i = 1; i <= m; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    g[x].push_back({y, z});
    g[y].push_back({x, z});
  }
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    for (int j = 1; j <= x; j++) {
      int y;
      scanf("%d", &y);
      vec[i].push_back(y);
    }
  }
  d[1] = 0;
  q.insert({d[1], 1});
  while (!q.empty()) {
    int v = q.begin()->second, start = d[v];
    int sz = vec[v].size() - 1;
    q.erase(q.begin());
    while (chek(v, 0, sz, start)) start++;
    for (int i = 0; i < g[v].size(); i++) {
      int to = g[v][i].first;
      int len = g[v][i].second;
      if (start + len < d[to]) {
        q.erase({d[to], to});
        d[to] = start + len;
        q.insert({d[to], to});
      }
    }
  }
  if (d[n] < INF)
    printf("%d ", d[n]);
  else
    printf("%d ", -1);
}
