#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
const int INF = 1 << 30;
vector<pair<int, int> > nbrs[MAX_N];
vector<int> ks[MAX_N];
int ds[MAX_N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--, b--;
    nbrs[a].push_back(pair<int, int>(b, c));
    nbrs[b].push_back(pair<int, int>(a, c));
  }
  for (int i = 0; i < n; i++) {
    int ki;
    scanf("%d", &ki);
    ks[i].resize(ki);
    for (int j = 0; j < ki; j++) scanf("%d", &ks[i][j]);
  }
  int st = 0, gl = n - 1;
  fill(ds, ds + n, INF);
  ds[st] = 0;
  priority_queue<pair<int, int> > q;
  q.push(pair<int, int>(0, st));
  while (!q.empty()) {
    pair<int, int> u = q.top();
    q.pop();
    int ud = -u.first, ui = u.second;
    if (ui == gl) break;
    vector<int> &ku = ks[ui];
    vector<int>::iterator vit = lower_bound(ku.begin(), ku.end(), ud);
    while (vit != ku.end() && *vit == ud) ud++, vit++;
    vector<pair<int, int> > &nbru = nbrs[ui];
    for (vector<pair<int, int> >::iterator vit = nbru.begin();
         vit != nbru.end(); vit++) {
      int v = vit->first, vd = ud + vit->second;
      if (ds[v] > vd) {
        ds[v] = vd;
        q.push(pair<int, int>(-vd, v));
      }
    }
  }
  printf("%d\n", (ds[gl] < INF) ? ds[gl] : -1);
  return 0;
}
