#include <bits/stdc++.h>
using namespace std;
static const int MAX = 100001;
static const int INF = numeric_limits<int>::max();
static int n, m;
static vector<pair<int, int> > g[MAX];
static map<int, int> sc[MAX];
static bool flag[MAX] = {};
int nextTime(int curPlanet, int curTime) {
  map<int, int>::iterator it = sc[curPlanet].find(curTime);
  if (it != sc[curPlanet].end()) {
    return curTime + it->second;
  }
  return curTime;
}
void proc(priority_queue<pair<int, int>, vector<pair<int, int> >,
                         greater<pair<int, int> > > &q,
          int curPlanet, int curTime) {
  int nt = nextTime(curPlanet, curTime);
  flag[curPlanet] = true;
  for (vector<pair<int, int> >::iterator it = g[curPlanet].begin();
       it != g[curPlanet].end(); ++it) {
    if (!flag[it->second]) {
      q.push(make_pair(nt + it->first, it->second));
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a].push_back(make_pair(c, b));
    g[b].push_back(make_pair(c, a));
  }
  vector<int> tmp;
  for (int i = 1; i <= n; ++i) {
    int len;
    cin >> len;
    tmp.clear();
    for (int j = 0; j < len; ++j) {
      int a;
      cin >> a;
      tmp.push_back(a);
    }
    int last = INF;
    int lastVal = 1;
    for (int j = len - 1; j >= 0; --j) {
      if (tmp[j] == last - 1) {
        sc[i][tmp[j]] = lastVal + 1;
        ++lastVal;
      } else {
        sc[i][tmp[j]] = lastVal = 1;
      }
      last = tmp[j];
    }
  }
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  proc(q, 1, 0);
  int res = INF;
  while (!q.empty()) {
    pair<int, int> e;
    bool found = false;
    while (!q.empty()) {
      e = q.top();
      q.pop();
      if (!flag[e.second]) {
        found = true;
        break;
      }
    }
    if (!found) break;
    int next = e.second;
    flag[next] = true;
    if (next == n) {
      res = e.first;
      break;
    }
    proc(q, next, e.first);
  }
  if (flag[n])
    cout << res << endl;
  else
    cout << -1 << endl;
}
