#include <bits/stdc++.h>
const int INF = 2000000000;
using namespace std;
inline int read() {
  int x(0), w(1);
  char c = getchar();
  while (c ^ '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') w = -1, c = getchar();
  while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar();
  return x * w;
}
struct NODE {
  int v, c;
};
int n, m, K, x, y, z, s, d[100010];
int head[100010], nxt[200010], to[200010], cost[200010], cnt;
vector<int> T[100010];
vector<int> len[100010];
priority_queue<NODE> q;
inline bool operator<(const NODE& a, const NODE& b) { return a.c > b.c; }
inline void add(int u, int v, int w) {
  to[++cnt] = v;
  cost[cnt] = w;
  nxt[cnt] = head[u];
  head[u] = cnt;
}
inline int wait_time(int u, int t) {
  if (t > T[u][T[u].size() - 2]) return 0;
  int l = 0, r = T[u].size() - 1, mid, pos;
  while (l <= r) {
    mid = (l + r) / 2;
    if (T[u][mid] >= t) {
      pos = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  if (T[u][pos] != t) return 0;
  return len[u][pos];
}
inline void dijkstra(int S) {
  for (int i = 0; i <= n; ++i) d[i] = INF;
  d[S] = wait_time(S, 0);
  q.push((NODE){S, d[S]});
  int u, dis, tmp;
  while (!q.empty()) {
    u = q.top().v;
    dis = q.top().c;
    q.pop();
    if (dis > d[u]) continue;
    for (int i = head[u]; i; i = nxt[i]) {
      tmp = d[u] + cost[i];
      if (to[i] != n) {
        tmp += wait_time(to[i], d[u] + cost[i]);
      }
      if (tmp < d[to[i]]) {
        d[to[i]] = tmp;
        q.push((NODE){to[i], d[to[i]]});
      }
    }
  }
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= m; ++i) {
    x = read(), y = read(), z = read();
    add(x, y, z);
    add(y, x, z);
  }
  int sz;
  for (int i = 1; i <= n; ++i) {
    K = read();
    s = 0;
    for (int j = 1; j <= K; ++j) {
      x = read();
      T[i].push_back(x);
      if (j > 1 && T[i][j - 1] - T[i][j - 2] > 1) {
        for (int k = s; k <= j - 2; ++k) {
          len[i].push_back(T[i][j - 2] - T[i][k] + 1);
        }
        s = j - 1;
      }
    }
    sz = T[i].size();
    for (int k = s; k < sz; ++k) {
      len[i].push_back(T[i][sz - 1] - T[i][k] + 1);
    }
    T[i].push_back(INF);
  }
  dijkstra(1);
  if (d[n] == INF)
    printf("-1");
  else
    printf("%d", d[n]);
  return 0;
}
