#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > adj[2 * 100007];
vector<int> vec[2 * 100007];
long long int cal(int x, long long int y) {
  for (int i = 0; i < vec[x].size(); i++)
    if (y < vec[x][i])
      return y;
    else if (y == vec[x][i])
      y++;
  return y;
}
long long int dijkstra(int n) {
  long long int ans[n + 3];
  fill(ans, ans + n + 3, 100000000000000007LL);
  priority_queue<pair<long long int, int>, vector<pair<long long int, int> >,
                 greater<pair<long long int, int> > >
      q;
  q.push(make_pair(0, 1));
  while (!q.empty()) {
    int u = q.top().second;
    long long int x = q.top().first;
    q.pop();
    if (u == n) break;
    x = cal(u, x);
    for (int i = 0; i < adj[u].size(); i++) {
      long long y = x + adj[u][i].second;
      if (ans[adj[u][i].first] > y) {
        ans[adj[u][i].first] = y;
        q.push(make_pair(y, adj[u][i].first));
      }
    }
  }
  return ans[n] >= 100000000000000007LL ? -1 : ans[n];
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    adj[u].push_back(make_pair(v, w));
    adj[v].push_back(make_pair(u, w));
  }
  for (int i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    while (k--) {
      int x;
      scanf("%d", &x);
      vec[i].push_back(x);
    }
  }
  cout << dijkstra(n) << endl;
  return 0;
}
