#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005, maxm = 200005;
const long long INF = 0X3f3f3f3f;
int nxt[maxm], to[maxm], head[maxn], e, n, m;
vector<pair<long long, int> > tim[maxn];
priority_queue<pair<long long, int>, vector<pair<long long, int> >,
               greater<pair<long long, int> > >
    q;
long long dis[maxn], ans, val[maxm];
bool vis[maxn];
void add_edge(int x, int y, int w) {
  to[e] = y;
  val[e] = w;
  nxt[e] = head[x];
  head[x] = e++;
}
int main() {
  memset(head, -1, sizeof(head));
  memset(dis, INF, sizeof(dis));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y, w;
    scanf("%d%d%d", &x, &y, &w);
    add_edge(x, y, w);
    add_edge(y, x, w);
  }
  for (int i = 1; i <= n; i++) {
    int t, f, s;
    scanf("%d", &t);
    for (int j = 1; j <= t; j++) {
      int x;
      scanf("%d", &x);
      tim[i].push_back(make_pair(x, 0));
    }
    sort(tim[i].begin(), tim[i].end());
    if (t) tim[i][t - 1].second = tim[i][t - 1].first + 1;
    for (int j = t - 1; j >= 1; j--) {
      if (tim[i][j - 1].first + 1 == tim[i][j].first)
        tim[i][j - 1].second = tim[i][j].second;
      else
        tim[i][j - 1].second = tim[i][j - 1].first + 1;
    }
  }
  int fd = 0;
  if (tim[1].size()) {
    int pos = lower_bound(tim[1].begin(), tim[1].end(), make_pair(0LL, 0)) -
              tim[1].begin();
    if (tim[1][pos].first == 0) fd = tim[1][pos].second;
  }
  q.push(make_pair(fd, 1));
  dis[1] = fd;
  ans = INF;
  while (!q.empty()) {
    pair<int, int> p = q.top();
    q.pop();
    int x = p.second, dd = p.first;
    vis[x] = 1;
    for (int i = head[x]; i + 1; i = nxt[i]) {
      int y = to[i];
      long long v = val[i] + dd;
      if (vis[y]) continue;
      if (y == n) ans = min(ans, v);
      if ((int)tim[y].size()) {
        int pos = lower_bound(tim[y].begin(), tim[y].end(), make_pair(v, 0)) -
                  tim[y].begin();
        if (tim[y][pos].first == v) v = tim[y][pos].second;
      }
      if (v < dis[y]) {
        dis[y] = v;
        q.push(make_pair(v, y));
      }
    }
  }
  if (ans == INF)
    puts("-1");
  else
    printf("%d", ans);
  return 0;
}
