#include <bits/stdc++.h>
using namespace std;
vector<long long> head[100000];
vector<long long> mom[100000];
int id;
int binsrach(long long tm) {
  int l = 0, r = head[id].size() - 1;
  int mid;
  while (l + 1 < r) {
    mid = (l + r) / 2;
    if (head[id][mid] < tm)
      l = mid;
    else
      r = mid;
  }
  if (tm == head[id][l]) return l;
  if (tm == head[id][r]) return r;
  return -1;
}
long long overhead(int f, long long tm) {
  if (head[f].size() == 0) return 0;
  id = f;
  int idx = binsrach(tm);
  if (idx == -1) {
    return 0;
  }
  return mom[f][idx] - tm;
}
int main() {
  int n, m, k, x, y, ki;
  int co, tij;
  scanf("%d %d", &n, &m);
  vector<vector<pair<int, long long> > > g(n);
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &x, &y, &co);
    x--;
    y--;
    g[x].push_back(make_pair(y, co));
    g[y].push_back(make_pair(x, co));
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &ki);
    for (int j = 0; j < ki; j++) {
      scanf("%d", &tij);
      head[i].push_back(tij);
      mom[i].push_back(tij + 1);
    }
    int prev = 2000000000;
    for (int j = mom[i].size() - 1; j >= 0; j--) {
      if (head[i][j] + 1 == prev) {
        mom[i][j] = mom[i][j + 1];
      }
      prev = head[i][j];
    }
  }
  int s = 0;
  vector<long long> d(n, 200000000000000000L), p(n);
  d[s] = 0;
  set<pair<long long, int> > q;
  q.insert(make_pair(d[s], s));
  while (!q.empty()) {
    int v = q.begin()->second;
    q.erase(q.begin());
    for (size_t j = 0; j < g[v].size(); ++j) {
      int to = g[v][j].first;
      long long len = g[v][j].second + overhead(v, d[v]);
      if (d[v] + len < d[to]) {
        q.erase(make_pair(d[to], to));
        d[to] = d[v] + len;
        p[to] = v;
        q.insert(make_pair(d[to], to));
      }
    }
  }
  if (d[n - 1] < 200000000000000000L) {
    printf("%I64d\n", d[n - 1]);
  } else
    printf("-1\n", d[n - 1]);
  return 0;
}
