#include <bits/stdc++.h>
using namespace std;
struct rec {
  int c, v;
  rec(int v0, int c0) : c(c0), v(v0) {}
};
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<rec>> v(n);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    v[a - 1].push_back(rec(b - 1, c));
    v[b - 1].push_back(rec(a - 1, c));
  }
  vector<set<int>> vk(n);
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int t;
      cin >> t;
      vk[i].insert(t);
    }
  }
  vector<int> res[2];
  res[0].resize(n, -1);
  res[1].resize(n, -1);
  res[0][0] = 0;
  struct vertex {
    int n, t;
    int d;
    vertex(int n0, int t0, int d0) : n(n0), t(t0), d(d0) {}
    bool operator<(const vertex &a) const { return a.d < d; }
  };
  priority_queue<vertex> q;
  q.push(vertex(0, 0, 0));
  while (!q.empty()) {
    auto cur = q.top();
    q.pop();
    if (cur.d > res[cur.t][cur.n]) continue;
    if (cur.t == 0) {
      auto it = vk[cur.n].find(cur.d);
      int vv = cur.d;
      while (it != vk[cur.n].end() && *it == vv) {
        it++;
        vv++;
      }
      if (res[1][cur.n] == -1 || res[1][cur.n] > vv) {
        res[1][cur.n] = vv;
        q.push(vertex(cur.n, 1, vv));
      }
    } else {
      for (auto &x : v[cur.n]) {
        if (res[0][x.v] == -1 || res[0][x.v] > cur.d + x.c) {
          res[0][x.v] = cur.d + x.c;
          q.push(vertex(x.v, 0, cur.d + x.c));
        }
      }
    }
  }
  cout << res[0][n - 1];
}
