#include <bits/stdc++.h>
using namespace std;
struct node {
  int to, cost;
};
vector<node> sq[200500];
map<int, bool> no[200500];
queue<int> q;
const long long maxd = (long long)210000000000;
long long dis[200500];
int n, m;
bool vis[200500];
void spfa() {
  int i;
  memset(vis, 0, sizeof(vis));
  for (i = 1; i <= n; i++) dis[i] = maxd;
  dis[1] = 0;
  q.push(1);
  vis[1] = 1;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    vis[v] = 0;
    int d = dis[v], len = sq[v].size();
    while (no[v][d]) d++;
    for (i = 0; i < len; i++) {
      int to = sq[v][i].to, cost = sq[v][i].cost;
      if (dis[to] > d + cost) {
        dis[to] = d + cost;
        if (!vis[to]) {
          q.push(to);
          vis[to] = 0;
        }
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  int i, j;
  for (i = 1; i <= m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    sq[u].push_back((node){v, w});
    sq[v].push_back((node){u, w});
  }
  for (i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    for (j = 1; j <= k; j++) {
      int tmp;
      scanf("%d", &tmp);
      no[i][tmp] = 1;
    }
  }
  spfa();
  if (dis[n] == maxd)
    printf("-1");
  else
    printf("%I64d", dis[n]);
  return 0;
}
