#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const int N = 1e5 + 5;
const ll uinf = 2e9;
vector<pair<int, int> > g[N];
vector<int> t[N];
set<pair<ll, int> > q;
ll dp[N];
inline int get(int x) {
  for (ll i = 0; i < 1e7; i++) {
    if (!binary_search(t[x].begin(), t[x].end(), dp[x] + i)) return i;
  }
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    g[u].push_back(make_pair(v, w));
    g[v].push_back(make_pair(u, w));
  }
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    for (int j = 1; j <= k; ++j) {
      int h;
      cin >> h;
      t[i].push_back(h);
    }
  }
  fill(dp, dp + N, uinf);
  int travel = 0;
  dp[1] = 0;
  q.insert(make_pair(dp[1], 1));
  while (!q.empty()) {
    int v = q.begin()->second;
    q.erase(q.begin());
    travel = dp[v] + get(v);
    for (int i = 0; i < (int)g[v].size(); i++) {
      int to = g[v][i].first, len = g[v][i].second;
      if (travel + len < dp[to]) {
        q.erase(make_pair(dp[to], to));
        dp[to] = travel + len;
        q.insert(make_pair(dp[to], to));
      }
    }
  }
  dp[n] = (dp[n] == uinf ? -1 : dp[n]);
  cout << dp[n] << '\n';
  return 0;
}
