#include <bits/stdc++.h>
using namespace std;
void addEdge(vector<pair<int, int>> graph[], int x, int y, int w) {
  graph[x].push_back(make_pair(y, w));
  graph[y].push_back(make_pair(x, w));
}
bool cmp2(const pair<int, int> &p1, const int v) {
  if (p1.first < v)
    return true;
  else
    return false;
}
void dijkstra(vector<pair<int, int>> graph[], vector<bool> &check,
              vector<int> &distance, int totalVertices, int source,
              vector<int> &parent, vector<pair<int, int>> distanceArray[]) {
  int i;
  vector<bool> marked(totalVertices, false);
  set<pair<int, int>> s1;
  s1.insert(make_pair(0, source));
  int value = 0;
  if (distanceArray[0].size() != 0) {
    if (distanceArray[0][0].first == 0) {
      value = value + distanceArray[0][0].second;
    }
  }
  distance[source] = value;
  parent[source] = source;
  check[source] = true;
  while (s1.empty() == 0) {
    auto itr = s1.begin();
    int deletedVertex = itr->second;
    int distFromSource = distance[itr->second];
    s1.erase(itr);
    marked[deletedVertex] = true;
    for (i = 0; i < graph[deletedVertex].size(); i++) {
      if (marked[graph[deletedVertex][i].first] == false &&
          check[graph[deletedVertex][i].first] == false) {
        int value = distFromSource + graph[deletedVertex][i].second;
        int size = distanceArray[graph[deletedVertex][i].first].size();
        if (distanceArray[graph[deletedVertex][i].first].size() != 0) {
          auto findingIterator = lower_bound(
              distanceArray[graph[deletedVertex][i].first].begin(),
              distanceArray[graph[deletedVertex][i].first].end(), value, cmp2);
          if (findingIterator->first == value) {
            value = value + findingIterator->second;
          }
        }
        s1.insert(make_pair(value, graph[deletedVertex][i].first));
        distance[graph[deletedVertex][i].first] = value;
        check[graph[deletedVertex][i].first] = true;
        parent[graph[deletedVertex][i].first] = deletedVertex;
      } else {
        int value = distFromSource + graph[deletedVertex][i].second;
        if (distanceArray[graph[deletedVertex][i].first].size() != 0) {
          auto findingIterator = lower_bound(
              distanceArray[graph[deletedVertex][i].first].begin(),
              distanceArray[graph[deletedVertex][i].first].end(), value, cmp2);
          if (findingIterator->first == value)
            value = value + findingIterator->second;
        }
        if (marked[graph[deletedVertex][i].first] == false &&
            value < distance[graph[deletedVertex][i].first]) {
          s1.erase(make_pair(distance[graph[deletedVertex][i].first],
                             graph[deletedVertex][i].first));
          parent[graph[deletedVertex][i].first] = deletedVertex;
          distance[graph[deletedVertex][i].first] = value;
          s1.insert(make_pair(distance[graph[deletedVertex][i].first],
                              graph[deletedVertex][i].first));
        }
      }
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> graph[n];
  int edge;
  cin >> edge;
  int i;
  for (i = 0; i < edge; i++) {
    int x, y, w;
    cin >> x >> y >> w;
    x--;
    y--;
    addEdge(graph, x, y, w);
  }
  int source = 0;
  vector<bool> check(n, false);
  vector<int> distance(n, -1);
  vector<int> parent(n, -1);
  vector<pair<int, int>> distanceArray[n];
  for (i = 0; i < n - 1; i++) {
    int x;
    cin >> x;
    for (int j = 0; j < x; j++) {
      int value;
      cin >> value;
      distanceArray[i].push_back(make_pair(value, 1));
    }
  }
  int x;
  cin >> x;
  for (int j = 0; j < x; j++) {
    int value;
    cin >> value;
  }
  for (i = 0; i < n; i++) {
    for (int j = distanceArray[i].size() - 1 - 1; j >= 0; j--) {
      if (distanceArray[i][j].first + 1 == distanceArray[i][j + 1].first) {
        distanceArray[i][j].second = distanceArray[i][j + 1].second + 1;
      }
    }
  }
  dijkstra(graph, check, distance, n, source, parent, distanceArray);
  cout << distance[n - 1] << endl;
}
