#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const string LN = "\n";
const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = (int)2e9 + 7;
const long long LINF = (long long)9e18 + 7;
bool insert(int k, int x1, int x2) { return (k >= x1 && k <= x2); }
const int MAXN = 60007;
const int P1 = 239017;
const int P2 = 353251;
const long long MOD = 1e9 + 7;
const long long MOD2 = 1e9 + 9;
const int l = 20;
int n, m;
vector<pair<int, int> > g[100007];
long long ans[100007];
vector<int> ti[100007];
set<pair<long long, int> > se;
void relax(int v) {
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i].first;
    int cost = g[v][i].second;
    if (ans[to] > ans[v] + cost) {
      se.erase(make_pair(ans[to], to));
      ans[to] = ans[v] + cost;
      se.insert(make_pair(ans[to], to));
    }
  }
}
void dij(int v) {
  for (int i = 0; i < n; i++) ans[i] = LINF;
  ans[v] = 0;
  se.insert(make_pair(0, v));
  while (se.size()) {
    auto d = *se.begin();
    se.erase(d);
    if (d.second == n - 1) cout << ans[d.second], exit(0);
    int timer = d.first;
    for (int i = 0; i < ti[d.second].size(); i++)
      if (ti[d.second][i] == timer) timer++;
    ans[d.second] = timer;
    relax(d.second);
  }
}
const bool is_testing = 0;
int main() {
  srand(time(NULL));
  if (is_testing) {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  }
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--;
    b--;
    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }
  for (int i = 0; i < n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      int x;
      scanf("%d", &x);
      ti[i].push_back(x);
    }
  }
  dij(0);
  cout << -1;
}
