#include <bits/stdc++.h>
using namespace std;
int n, m;
const int MAXN = 1e5 + 10;
vector<pair<int, int> > g[MAXN];
map<int, int> mp[MAXN];
long long dist[MAXN];
void dijkstra(int x) {
  memset(dist, -1, sizeof(dist));
  priority_queue<pair<long long, int> > q;
  dist[x] = 0;
  q.push({0, x});
  while (!q.empty()) {
    x = q.top().second;
    long long c = -q.top().first;
    q.pop();
    long long adc = 0;
    if (mp[x].count(c)) adc = mp[x][c];
    if (dist[x] != c) continue;
    for (long long i = 0; i < g[x].size(); i++) {
      int y = g[x][i].first;
      long long c = g[x][i].second;
      if (dist[y] < 0 || dist[x] + c + adc < dist[y])
        dist[y] = dist[x] + c + adc, q.push({-dist[y], y});
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  for (long long i = 0; i < n; i++) {
    int k;
    cin >> k;
    if (k == 0) continue;
    vector<int> v(k);
    for (long long j = 0; j < k; j++) cin >> v[j];
    mp[i][v[k - 1]] = 1;
    for (int j = k - 2; j >= 0; j--) {
      if (v[j + 1] - v[j] == 1) {
        mp[i][v[j]] = mp[i][v[j + 1]] + 1;
      } else {
        mp[i][v[j]] = 1;
      }
    }
  }
  dijkstra(0);
  cout << dist[n - 1] << "\n";
  return 0;
}
