#include <bits/stdc++.h>
using namespace std;
const long long N = 1e+5, INF = 1e+12;
int n, m;
vector<pair<int, long long> > g[N];
long long dist[N];
map<long long, long long> used[N];
void read() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    dist[i] = INF;
  }
  for (int i = 0; i < m; i++) {
    static int u, v, c;
    cin >> u >> v >> c;
    u--;
    v--;
    g[u].push_back(make_pair(v, c));
    g[v].push_back(make_pair(u, c));
  }
  for (int i = 0; i < n; i++) {
    static int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      static int buf;
      cin >> buf;
      used[i][buf] = -1;
    }
  }
}
long long relax(int u, long long t) {
  if (used[u].find(t) == used[u].end()) return t;
  if (used[u][t] != -1) return used[u][t];
  return used[u][t] = relax(u, t + 1);
}
void deikstra(int u) {
  priority_queue<pair<long long, int> > q;
  dist[u] = relax(u, 0);
  q.push(make_pair(-dist[u], u));
  while (!q.empty()) {
    int u = q.top().second;
    long long len = -q.top().first;
    q.pop();
    if (len > dist[u]) continue;
    for (int i = 0; i < (int)g[u].size(); i++) {
      int v = g[u][i].first;
      len = (v == n - 1 ? dist[u] + g[u][i].second
                        : relax(v, dist[u] + g[u][i].second));
      if (len < dist[v]) {
        dist[v] = len;
        q.push(make_pair(-len, v));
      }
    }
  }
}
int main() {
  read();
  deikstra(0);
  cout << (dist[n - 1] != INF ? dist[n - 1] : -1);
  return 0;
}
