#include <bits/stdc++.h>
using namespace std;
class node {
 public:
  long long int vertex;
  long long int weight;
  bool operator<(const node& p) const { return weight > p.weight; }
};
long long int n, m;
long long int* arr[100100];
vector<node> vec[100100];
long long int con[100100];
long long int binS(long long int l, long long int h, long long int val,
                   long long int x) {
  while (h >= l) {
    long long int m = (h + l) / 2;
    if (arr[x][m] == val)
      return m;
    else if (arr[x][m] > val) {
      h = m - 1;
    } else {
      l = m + 1;
    }
  }
  return -1;
}
long long int spec_binS(long long int l, long long int h, long long int in,
                        long long int x) {
  long long int ans = -1;
  while (h >= l) {
    long long int m = (h + l) / 2;
    long long int u, v;
    u = m - in;
    v = arr[x][m] - arr[x][in];
    if (u >= 0 && v >= 0 && u == v) {
      ans = m;
      l = m + 1;
    } else if (arr[x][m] > arr[x][in]) {
      h = m - 1;
    } else {
      l = m + 1;
    }
  }
  return ans;
}
long long int extra_cal(long long int ver, long long int d) {
  long long int u = binS(1, con[ver], d, ver);
  if (u == -1) return 0;
  long long int v = spec_binS(1, con[ver], u, ver);
  return (v - u) + 1;
}
long long int dis[100100];
long long int par[100100];
void bfs() {
  priority_queue<node> q;
  for (long long int i = 1; i <= 100050; i++) dis[i] = 900000000000000000;
  long long int pp = extra_cal(1, 0);
  dis[1] = pp;
  node t;
  t.vertex = 1;
  t.weight = 0;
  q.push(t);
  while (q.size() != 0) {
    node t = q.top();
    long long int u = t.vertex;
    for (long long int i = 0; i < vec[u].size(); i++) {
      long long int v = vec[u][i].vertex;
      long long int w = vec[u][i].weight;
      long long int kk = extra_cal(v, dis[u] + w);
      if (dis[u] + w + kk < dis[v] && par[u] != v) {
        par[v] = u;
        dis[v] = dis[u] + w + kk;
        if (v == n) dis[v] = dis[v] - kk;
        node t;
        t.vertex = v;
        t.weight = dis[v];
        q.push(t);
      }
    }
    q.pop();
  }
  if (dis[n] != 900000000000000000)
    cout << dis[n] << endl;
  else
    cout << -1 << endl;
}
int main() {
  cin >> n >> m;
  for (long long int i = 1; i <= m; i++) {
    long long int u, v, w;
    cin >> u >> v >> w;
    node t;
    t.vertex = v;
    t.weight = w;
    vec[u].push_back(t);
    t.vertex = u;
    t.weight = w;
    vec[v].push_back(t);
  }
  for (long long int i = 1; i <= n; i++) {
    long long int k;
    cin >> k;
    con[i] = k;
    arr[i] = new long long int[k + 10];
    for (long long int j = 1; j <= k; j++) {
      long long int p;
      cin >> p;
      arr[i][j] = p;
    }
  }
  bfs();
  return 0;
}
