#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, w, sz[100011], d[100011];
vector<int> dly[100011];
vector<pair<int, int>> g[100011];
priority_queue<pair<int, int>> pq;
int main() {
  memset(d, 63, sizeof(d));
  scanf("%d %d", &n, &m);
  for (int(i) = int(1); (i) <= int(m); (i)++)
    scanf("%d %d %d", &a, &b, &w), g[a].emplace_back(w, b),
        g[b].emplace_back(w, a);
  for (int(i) = int(1); (i) <= int(n); (i)++) {
    scanf("%d", &sz[i]);
    dly[i].resize(sz[i]);
    for (int(j) = int(0); (j) <= int(sz[i] - 1); (j)++) scanf("%d", &dly[i][j]);
  }
  d[1] = 0, pq.emplace(0, 1);
  while (!pq.empty()) {
    w = -pq.top().first;
    a = pq.top().second;
    pq.pop();
    if (w != d[a]) continue;
    if (a == n) break;
    for (int i = 0; i < sz[a]; i++)
      if (dly[a][i] == d[a]) d[a]++;
    for (int i = 0; i < g[a].size(); i++)
      if (d[g[a][i].second] > d[a] + g[a][i].first)
        d[g[a][i].second] = d[a] + g[a][i].first,
        pq.emplace(-d[g[a][i].second], g[a][i].second);
  }
  if (d[n] == 0x3f3f3f3f)
    printf("-1\n");
  else
    printf("%d\n", d[n]);
}
