#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, m, d[N];
vector<pair<int, int>> v[N];
vector<int> u[N], p[N];
priority_queue<pair<int, int>> q;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    v[x].push_back({y, z});
    v[y].push_back({x, z});
  }
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d", &x);
    if (!x) continue;
    while (x--) {
      scanf("%d", &y);
      u[i].push_back(y);
    }
    p[i] = vector<int>(u[i].size());
    p[i][u[i].size() - 1] = u[i].size() - 1;
    for (int j = (int)u[i].size() - 2; j >= 0; j--) {
      if (u[i][j + 1] - u[i][j] != 1)
        p[i][j] = j;
      else
        p[i][j] = p[i][j + 1];
    }
  }
  for (int i = 1; i <= n; i++) d[i] = -1;
  q.push({0, 1});
  while (!q.empty()) {
    int c = q.top().second, de = q.top().first;
    q.pop();
    if (d[c] != -1) continue;
    d[c] = -de;
    int pos, time;
    if (u[c].empty())
      time = d[c];
    else {
      pos = lower_bound(u[c].begin(), u[c].end(), d[c]) - u[c].begin();
      if (u[c][pos] != d[c])
        time = d[c];
      else
        time = u[c][p[c][pos]] + 1;
    }
    for (auto i : v[c]) q.push({-time - i.second, i.first});
  }
  printf("%d", d[n]);
  return 0;
}
