#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const long double pi = acos(-1.0);
const int inf = 2 * 1e+9;
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
int xabs(int a) { return a >= 0 ? a : -a; }
int sign(int a) { return (a < 0) ? -1 : 1; }
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int> > > g(n);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }
  vector<vector<int> > wait(n);
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    for (int k = 0; k < t; k++) {
      int a;
      cin >> a;
      wait[i].push_back(a);
    }
  }
  set<pair<int, int> > q;
  vector<int> d(n, inf);
  d[0] = 0;
  q.insert(make_pair(d[0], 0));
  while (!q.empty()) {
    int v = (*q.begin()).second;
    int curTime = (*q.begin()).first;
    q.erase(q.begin());
    for (int i = 0; i < wait[v].size(); i++) {
      if (curTime == wait[v][i]) curTime++;
    }
    if (v != n - 1) d[v] = curTime;
    for (int i = 0; i < g[v].size(); i++) {
      int to = g[v][i].first;
      int cost = g[v][i].second;
      if (d[to] > d[v] + cost) {
        q.erase(make_pair(d[to], to));
        d[to] = d[v] + cost;
        q.insert(make_pair(d[to], to));
      }
    }
  }
  if (d[n - 1] == inf)
    cout << -1 << endl;
  else
    cout << d[n - 1] << endl;
  return 0;
}
