#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int n, m;
set<int> ttable[maxn];
struct edge {
  int val, to;
};
vector<edge> rtable[maxn];
int dis[maxn];
int vis[maxn];
int gettime(int num, int pt) {
  while (ttable[pt].find(num) != ttable[pt].end()) {
    num++;
  }
  return num;
}
queue<int> myque;
void spfa(int s) {
  memset(dis, 0x3f, sizeof(dis));
  memset(vis, 0, sizeof(vis));
  dis[s] = 0;
  myque.push(s);
  vis[s] = 1;
  while (!myque.empty()) {
    int tmp = myque.front();
    myque.pop();
    vis[tmp] = 0;
    int dptime = gettime(dis[tmp], tmp);
    for (int i = 0; i < rtable[tmp].size(); i++) {
      edge tempe = rtable[tmp][i];
      int v = tempe.to;
      if (dptime + tempe.val < dis[v]) {
        dis[v] = dptime + tempe.val;
        if (!vis[v]) {
          vis[v] = 1;
          myque.push(v);
        }
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    edge temp1, temp2;
    scanf("%d%d%d", &a, &b, &c);
    temp1.to = a;
    temp1.val = c;
    temp2.to = b;
    temp2.val = c;
    rtable[a].push_back(temp2);
    rtable[b].push_back(temp1);
  }
  for (int i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      int tp;
      scanf("%d", &tp);
      ttable[i].insert(tp);
    }
  }
  spfa(1);
  if (dis[n] == 0x3f3f3f3f) {
    printf("-1\n");
  } else
    printf("%d\n", dis[n]);
  return 0;
}
