#include <bits/stdc++.h>
using namespace std;
struct edge {
  int a, b;
  long long c;
  edge() {}
  edge(int a, int b, long long c) : a(a), b(b), c(c) {}
};
struct phase {
  int v;
  long long w;
  phase() {}
  phase(int v, long long w) : v(v), w(w) {}
  bool operator<(const phase &r) const { return w > r.w; }
};
int N, M;
vector<edge> con[100005];
vector<long long> arrive[100005];
map<long long, long long> linkt[100005];
int K[100005];
bool vst[100005];
long long dist[100005];
priority_queue<phase> Q;
int main(void) {
  scanf("%d %d", &N, &M);
  for (int i = 1; i <= M; i++) {
    int a, b;
    long long c;
    scanf("%d %d %I64d", &a, &b, &c);
    con[a].push_back(edge(a, b, c));
    con[b].push_back(edge(b, a, c));
  }
  for (int i = 1; i <= N; i++) {
    scanf("%d", &K[i]);
    for (int j = 0; j < K[i]; j++) {
      int t;
      scanf("%d", &t);
      arrive[i].push_back(t);
    }
    if (K[i]) {
      linkt[i][arrive[i][K[i] - 1]] = arrive[i][K[i] - 1] + 1;
      for (int j = K[i] - 2; j >= 0; j--) {
        if (arrive[i][j] + 1 == arrive[i][j + 1])
          linkt[i][arrive[i][j]] = linkt[i][arrive[i][j + 1]];
        else
          linkt[i][arrive[i][j]] = arrive[i][j] + 1;
      }
    }
  }
  long long tt = 0;
  if (linkt[1].find(tt) != linkt[1].end()) tt = linkt[1][tt];
  Q.push(phase(1, tt));
  while (Q.size()) {
    phase pivot = Q.top();
    Q.pop();
    int pv;
    long long pw;
    pv = pivot.v, pw = pivot.w;
    if (vst[pv]) continue;
    vst[pv] = true;
    dist[pv] = pw;
    for (int i = 0; i < con[pv].size(); i++) {
      int u = con[pv][i].b;
      long long w = con[pv][i].c;
      if (vst[u]) continue;
      long long t = pw + w;
      if (linkt[u].find(t) != linkt[u].end() && u != N) t = linkt[u][t];
      Q.push(phase(u, t));
    }
  }
  if (!vst[N])
    printf("-1\n");
  else
    printf("%I64d\n", dist[N]);
  return 0;
}
