#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const double eps = 1e-8;
const int iinf = INT_MAX;
const long long linf = 2e18;
const double dinf = 1e30;
const int MOD = 1000000007;
int n, m, top = 1;
set<int> s[N];
int dis[N], head[N];
struct edge {
  int to, nxt, w;
} e[N << 1];
void add(int a, int b, int w) {
  e[++top] = (edge){b, head[a], w};
  head[a] = top;
}
struct node {
  int x, len;
  bool operator<(const node &a) const { return len > a.len; }
};
void dij() {
  priority_queue<node> q;
  for (int i = 1; i <= n; i++) dis[i] = iinf;
  dis[1] = 0;
  q.push((node){1, 0});
  while (!q.empty()) {
    node now = q.top();
    q.pop();
    int tim = now.len;
    while (s[now.x].count(tim)) tim++;
    if (dis[now.x] != now.len) continue;
    for (int i = head[now.x]; i; i = e[i].nxt) {
      int to = e[i].to;
      if (dis[to] > tim + e[i].w) {
        dis[to] = tim + e[i].w;
        q.push((node){to, dis[to]});
      }
    }
  }
}
signed main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    add(x, y, z);
    add(y, x, z);
  }
  for (int i = 1; i <= n; i++) {
    int sum, x;
    scanf("%d", &sum);
    while (sum--) scanf("%d", &x), s[i].insert(x);
  }
  dij();
  if (dis[n] == iinf)
    cout << -1 << '\n';
  else
    cout << dis[n] << '\n';
  return 0;
}
