#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30) - 1;
const long long LLINF = ((long long)1 << 62) - 1;
vector<long long> T[100005];
typedef struct Edge {
  int vex, value;
  struct Edge *next;
} Edge;
Edge *node[100005], e[100005 << 1];
int nnode, ne, prior[100005];
int heap[100005], pos[100005], heapsize;
long long d[100005];
void heap_init() {
  int i;
  heapsize = nnode;
  for (i = 1; i <= nnode; i++) {
    heap[i] = i;
    pos[i] = i;
    d[i] = LLINF;
  }
  return;
}
void heap_exchange(int a, int b) {
  int apos, bpos;
  apos = pos[a];
  bpos = pos[b];
  heap[apos] = b;
  heap[bpos] = a;
  pos[a] = bpos;
  pos[b] = apos;
  return;
}
void heap_adjust(int a) {
  int po;
  po = pos[a];
  while (po > 1 && d[heap[po / 2]] > d[a]) {
    heap_exchange(a, heap[po / 2]);
    po /= 2;
  }
  while (po * 2 + 1 <= heapsize &&
         (d[a] > d[heap[po * 2]] || d[a] > d[heap[po * 2 + 1]])) {
    if (d[heap[po * 2 + 1]] > d[heap[po * 2]]) {
      heap_exchange(a, heap[po * 2]);
      po *= 2;
    } else {
      heap_exchange(a, heap[po * 2 + 1]);
      po = po * 2 + 1;
    }
  }
  if (po * 2 <= heapsize && d[heap[po * 2]] < d[a]) {
    heap_exchange(a, heap[po * 2]);
    po *= 2;
  }
  return;
}
int heap_pop() {
  int res;
  res = heap[1];
  heap_exchange(heap[1], heap[heapsize]);
  heapsize--;
  heap_adjust(heap[1]);
  return res;
}
void dijkstra_init() {
  heap_init();
  return;
}
long long Bin(int who, long long can) {
  int l = 0, r = T[who].size() - 1, mid;
  while (l + 1 < r) {
    mid = (l + r) / 2;
    if (T[who][mid] <= can) {
      l = mid;
    } else {
      r = mid;
    }
  }
  long long when = can;
  while (l < T[who].size() && T[who][l] == when) {
    when++;
    l++;
  }
  return when;
}
long long dijkstra(int s, int o) {
  int i, now;
  dijkstra_init();
  Edge *p;
  d[s] = 0;
  heap_adjust(s);
  while (heapsize) {
    now = heap_pop();
    if (d[now] == LLINF) {
      break;
    }
    if (now == o) {
      return d[now];
    }
    long long gogogo = d[now];
    if (!T[now].empty()) gogogo = Bin(now, d[now]);
    for (p = node[now]; p; p = p->next) {
      if (p->value + gogogo < d[p->vex]) {
        d[p->vex] = p->value + gogogo;
        prior[p->vex] = now;
        heap_adjust(p->vex);
      }
    }
  }
  return -1;
}
int addedge(int v, int w, int key) {
  e[ne].next = node[v];
  e[ne].vex = w;
  e[ne].value = key;
  node[v] = e + ne;
  ne++;
  return 1;
}
void dijinit() {
  ne = 0;
  memset(node, 0, sizeof(node));
}
int main() {
  int tmp;
  int i, j, k;
  dijinit();
  scanf("%d%d", &nnode, &i);
  while (i--) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    addedge(u, v, w);
    addedge(v, u, w);
  }
  for (i = 1; i <= nnode; i++) T[i].clear();
  for (i = 1; i <= nnode; i++) {
    scanf("%d", &k);
    for (j = 0; j < k; j++) {
      scanf("%d", &tmp);
      T[i].push_back(tmp);
    }
  }
  printf("%I64d\n", dijkstra(1, nnode));
  return 0;
}
