#include <bits/stdc++.h>
using namespace std;
struct Node {
  long long a, v;
  Node(long long a, long long v) : a(a), v(v) {}
  Node() {}
};
const long long maxn = 110000;
vector<Node> adlist[maxn];
bool visited[maxn];
long long dfa[maxn];
long long dad[maxn];
long long n, m;
long long atIndex[maxn];
long long k[maxn];
vector<long long> times[maxn];
long long s, t;
bool find = false;
vector<long long> counts[maxn];
bool operator<(Node a, Node b) {
  if (a.v < b.v) return true;
  if (a.v == b.v && a.a < b.a) return true;
  return false;
}
void initialize() {
  for (long long i = 0; i < maxn; i++) dad[i] = dfa[i] = -1;
  dfa[0] = 0;
}
long long findTime(long long index, long long myTime, long long indexOfArray) {
  long long megh = 0;
  for (long long i = indexOfArray; i < k[index]; i++) {
    if (times[index][i] == myTime) {
      megh++;
      myTime++;
    } else
      return megh;
  }
  return megh;
}
long long binS(long long myTime, long long index, long long f, long long l) {
  long long y = (f + l) / 2;
  if (f == l - 1) {
    if (times[index][f] == myTime) return f;
    return -1;
  }
  if (times[index][y] > myTime) return binS(myTime, index, f, y);
  return binS(myTime, index, y, l);
}
int gtmp[maxn];
void fill(int index1) {
  gtmp[k[index1] - 1] = 1;
  for (int i = k[index1] - 2; i >= 0; i--) {
    if (times[index1][i] == times[index1][i + 1] - 1)
      gtmp[i] = gtmp[i + 1] + 1;
    else
      gtmp[i] = 1;
  }
}
void input() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    adlist[a].push_back(Node(b, c));
    adlist[b].push_back(Node(a, c));
  }
  for (long long i = 0; i < n; i++) {
    cin >> k[i];
    for (long long il = 0; il < k[i]; il++) {
      long long l;
      cin >> l;
      times[i].push_back(l);
    }
  }
  for (int i = 0; i < n; i++) {
    if (!k[i]) continue;
    fill(i);
    for (int hi = 0; hi < k[i]; hi++) counts[i].push_back(gtmp[hi]);
  }
}
void find1() {
  set<Node> pq;
  visited[s] = true;
  for (long long i = 0; i < adlist[s].size(); i++) {
    dad[adlist[s][i].a] = s;
    dfa[adlist[s][i].a] = adlist[s][i].v + dfa[s];
    if (k[adlist[s][i].a] && adlist[s][i].a != t) {
      long long index1 =
          binS(dfa[adlist[s][i].a], adlist[s][i].a, 0, k[adlist[s][i].a]);
      if (index1 != -1) {
        dfa[adlist[s][i].a] += counts[adlist[s][i].a][index1];
      }
    }
    pq.insert(Node(adlist[s][i].a, dfa[adlist[s][i].a]));
  }
  while (pq.size()) {
    long long g = pq.begin()->a;
    visited[g] = true;
    pq.erase(Node(g, dfa[g]));
    for (long long j = 0; j < adlist[g].size(); j++) {
      if (visited[adlist[g][j].a]) continue;
      long long newTime = dfa[g] + adlist[g][j].v;
      if (adlist[g][j].a != t) {
        if (k[adlist[g][j].a]) {
          long long newIndex =
              binS(newTime, adlist[g][j].a, 0, k[adlist[g][j].a]);
          if (newIndex != -1) {
            newTime += counts[adlist[g][j].a][newIndex];
          }
        }
      }
      if (dfa[adlist[g][j].a] == -1 || newTime < dfa[adlist[g][j].a]) {
        pq.erase(Node(adlist[g][j].a, dfa[adlist[g][j].a]));
        dfa[adlist[g][j].a] = newTime;
        pq.insert(Node(adlist[g][j].a, dfa[adlist[g][j].a]));
      }
    }
  }
}
void output() {
  if (dfa[t] == -1) {
    cout << -1 << endl;
    return;
  }
  cout << dfa[t] << endl;
}
int main() {
  initialize();
  input();
  s = 0;
  if (k[0]) {
    long long u1 = binS(0, 0, 0, k[0]);
    if (u1 != -1) {
      dfa[0] = counts[0][u1];
    }
  }
  t = n - 1;
  find1();
  output();
  return 0;
}
