#include <bits/stdc++.h>
using namespace std;
struct no {
  int v;
  long long dist;
  bool operator<(const no &e) const { return dist > e.dist; }
};
vector<int> grafo[100010];
vector<int> cst[100010];
vector<int> k[100010];
vector<int> k_acc[100010];
int n, m;
long long c[100010];
int parent[100010];
int ini, fim, queue1[100010];
priority_queue<no> Q;
void PQinit() {
  ini = 0;
  fim = 0;
}
void PQinsert(int a) { queue1[fim++] = a; }
int PQempty() {
  if (ini == fim) return 1;
  return 0;
}
int PQdelmin() {
  long long min = -1, min_idx;
  for (int i = ini; i < fim; i++) {
    if (c[queue1[i]] < min || min == -1) {
      min = c[queue1[i]];
      min_idx = i;
    }
  }
  int temp = queue1[min_idx];
  queue1[min_idx] = queue1[ini];
  queue1[ini] = temp;
  return queue1[ini++];
}
void printqueue1() {
  cout << "printing queue1" << endl;
  for (int i = ini; i < fim; i++) {
    cout << queue1[i] << " (" << c[queue1[i]] << ") ";
  }
  cout << endl;
}
void acha_menor_caminho(int v) {
  int w0, w;
  long long bla;
  for (int i = 0; i <= n; i++) {
    parent[i] = -1;
    c[i] = 10000000000;
  }
  parent[v] = v;
  bla = 0;
  for (int j = 0; j < k[1].size(); j++) {
    if (k[1][j] == bla) bla++;
  }
  c[v] = bla;
  PQinit();
  PQinsert(v);
  for (int i = 1; i <= n; i++) {
    if (i != v) {
      PQinsert(i);
    }
  }
  while (!PQempty()) {
    w0 = PQdelmin();
    if (c[w0] == -1) break;
    for (int i = 0; i < grafo[w0].size(); i++) {
      w = grafo[w0][i];
      bla = c[w0] + cst[w0][i];
      if (w != n) {
        for (int j = 0; j < k[w].size(); j++) {
          if (k[w][j] == bla) bla++;
        }
      }
      if (c[w] > bla) {
        c[w] = bla;
        parent[w] = w0;
      }
    }
  }
}
void acha_menor_caminho2(int v) {
  no w0, w, e;
  long long bla;
  for (int i = 0; i <= n; i++) {
    parent[i] = -1;
    c[i] = 10000000000;
  }
  parent[v] = v;
  bla = 0;
  for (int j = 0; j < k[1].size(); j++) {
    if (k[1][j] == bla) bla++;
  }
  e.v = v;
  e.dist = bla;
  c[v] = bla;
  Q.push(e);
  for (int i = 1; i <= n; i++) {
    if (i != v) {
      e.v = i;
      e.dist = 10000000000;
      Q.push(e);
    }
  }
  while (!Q.empty()) {
    w0 = Q.top();
    Q.pop();
    for (int i = 0; i < grafo[w0.v].size(); i++) {
      w.v = grafo[w0.v][i];
      bla = w0.dist + cst[w0.v][i];
      if (w.v != n) {
        int ini = 0, fim = k[w.v].size();
        int j;
        for (j = (ini + fim) / 2; fim > ini; j = (ini + fim) / 2) {
          if (k[w.v][j] == bla) {
            bla = k_acc[w.v][j];
            break;
          } else if (k[w.v][j] < bla) {
            ini = j + 1;
          } else {
            fim = j;
          }
        }
      }
      if (c[w.v] > bla) {
        w.dist = bla;
        c[w.v] = bla;
        Q.push(w);
        parent[w.v] = w0.v;
      }
    }
  }
}
int main() {
  int a, b, z;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> z;
    grafo[a].push_back(b);
    cst[a].push_back(z);
    grafo[b].push_back(a);
    cst[b].push_back(z);
  }
  for (int i = 1; i <= n; i++) {
    cin >> a;
    for (int j = 0; j < a; j++) {
      cin >> b;
      k[i].push_back(b);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < k[i].size(); j++) {
      k_acc[i].push_back(0);
    }
  }
  for (int i = 1; i <= n; i++) {
    int sz = k_acc[i].size();
    if (sz == 0) continue;
    k_acc[i][sz - 1] = k[i][sz - 1] + 1;
    for (int j = k[i].size() - 2; j >= 0; j--) {
      if (k[i][j] == k[i][j + 1] - 1)
        k_acc[i][j] = k_acc[i][j + 1];
      else
        k_acc[i][j] = k[i][j] + 1;
    }
  }
  acha_menor_caminho2(1);
  if (c[n] == 10000000000)
    cout << -1 << endl;
  else
    cout << c[n] << endl;
  return 0;
}
