#include <bits/stdc++.h>
using namespace std;
void show() { cout << '\n'; }
template <typename T, typename... Args>
void show(T a, Args... args) {
  cout << a << " ";
  show(args...);
}
template <typename T>
void show_c(T& a) {
  for (auto& x : a) {
    cout << x << " ";
  }
  cout << endl;
}
vector<int> edge[100100], cost[100100];
bool vis[100100];
vector<int> wait[100100];
vector<int> jump[100100];
struct node {
  int val, city;
  bool operator<(const node& p) const { return val > p.val; }
};
int dijkstra(int s, int f) {
  memset((vis), 0, sizeof(vis));
  ;
  node place, temp, u;
  place.val = 0;
  place.city = s;
  priority_queue<node> q;
  q.push(place);
  while (!q.empty()) {
    temp = q.top();
    q.pop();
    if (temp.city == f) return temp.val;
    if (vis[temp.city]) continue;
    vis[temp.city] = true;
    int delay = temp.val;
    if (find(wait[temp.city].begin(), wait[temp.city].end(), temp.val) !=
        wait[temp.city].end()) {
      delay = jump[temp.city][find(wait[temp.city].begin(),
                                   wait[temp.city].end(), temp.val) -
                              wait[temp.city].begin()];
    }
    for (int i = 0; i < edge[temp.city].size(); ++i) {
      u.val = cost[temp.city][i] + delay;
      u.city = edge[temp.city][i];
      if (!vis[u.city]) q.push(u);
    }
  }
  return -1;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int u, v, w;
  while (m--) {
    scanf("%d %d %d", &u, &v, &w);
    edge[u].push_back(v);
    cost[u].push_back(w);
    edge[v].push_back(u);
    cost[v].push_back(w);
  }
  int tmp;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &tmp);
    for (int j = 0; j < tmp; ++j) {
      scanf("%d", &u);
      wait[i].push_back(u);
    }
    if (tmp > 0) {
      jump[i].resize(tmp);
      jump[i][tmp - 1] = wait[i].back() + 1;
      for (int j = tmp - 2; j >= 0; --j) {
        if (wait[i][j] + 1 == wait[i][j + 1]) {
          jump[i][j] = jump[i][j + 1];
        } else {
          jump[i][j] = wait[i][j] + 1;
        }
      }
    }
  }
  printf("%d\n", dijkstra(1, n));
  return 0;
}
