#include <bits/stdc++.h>
using namespace std;
int stmp;
const int MAX = 100000;
const int INF = 1000000001;
vector<pair<int, int> > G[MAX];
vector<int> T[MAX];
int n, m;
int dijkstra() {
  vector<long long> D(n, -1);
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      Q;
  Q.push(make_pair(0, 0));
  D[0] = 0;
  while (!Q.empty()) {
    long long d = Q.top().first;
    int v = Q.top().second;
    Q.pop();
    if (D[v] != d) continue;
    vector<int>::iterator it = lower_bound((T[v]).begin(), (T[v]).end(), d);
    if (it != T[v].end() && *it == d) {
      while (it != T[v].end() && *it == d) {
        ++it;
        ++d;
      }
    }
    for (__typeof((G[v]).begin()) u = (G[v]).begin(); u != (G[v]).end(); ++u)
      if (D[u->first] == -1 || d + u->second < D[u->first]) {
        D[u->first] = d + u->second;
        Q.push(make_pair(D[u->first], u->first));
      }
  }
  return D[n - 1];
}
int main(int argc, char *argv[]) {
  stmp = scanf("%d %d", &n, &m);
  while (m--) {
    int a, b, c;
    stmp = scanf("%d %d %d", &a, &b, &c);
    --a, --b;
    G[a].push_back(make_pair(b, c));
    G[b].push_back(make_pair(a, c));
  }
  for (int i = 0; i < (n); ++i) {
    int k;
    stmp = scanf("%d", &k);
    while (k--) {
      int x;
      stmp = scanf("%d", &x);
      T[i].push_back(x);
    }
    sort((T[i]).begin(), (T[i]).end());
  }
  printf("%d\n", dijkstra());
  return 0;
}
