#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, m;
long long dis[N];
bool vis[N];
vector<pair<int, int> > g[N];
map<pair<int, long long>, long long> M;
struct node {
  long long dist;
  int u;
  inline bool operator<(const node &p) const { return dist > p.dist; }
};
long long Solve(void) {
  fill(vis + 1, vis + 1 + n, 0);
  fill(dis + 1, dis + 1 + n, -1);
  priority_queue<node> q;
  dis[1] = M[make_pair(1, 0)];
  q.push((node){0LL, 1});
  while (!q.empty()) {
    node now = q.top();
    q.pop();
    int x = now.u;
    if (vis[x]) continue;
    vis[x] = 1;
    for (int i = 0; i < (int)g[x].size(); ++i) {
      int y = g[x][i].first, d = g[x][i].second;
      long long tmp = M[make_pair(y, dis[x] + d)];
      if (tmp == 0 || y == n) tmp = dis[x] + d;
      if (dis[y] == -1 || dis[y] > tmp) dis[y] = tmp, q.push((node){tmp, y});
    }
  }
  return dis[n];
}
int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    g[x].push_back(make_pair(y, z));
    g[y].push_back(make_pair(x, z));
  }
  for (int x = 1; x <= n; ++x) {
    int num, t[N], p = 1;
    scanf("%d", &num);
    for (int i = 1; i <= num; ++i) {
      scanf("%d", t + i);
      if (i > 1 && t[i] - t[i - 1] > 1) {
        for (int j = p; j < i; ++j) M[make_pair(x, t[j])] = t[i - 1] + 1;
        p = i;
      }
    }
    for (int i = p; i <= num; ++i) M[make_pair(x, t[i])] = t[num] + 1;
  }
  printf("%lld\n", Solve());
  return 0;
}
