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3 9
9 10
 10 10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 1
 3 0
 6 6
1 2
2 3
3 1
4 5
5 6
6 4
 10 0
 9 15
1 2
2 3
3 1
1 4
4 5
5 1
1 6
6 7
7 1
1 8
8 9
9 1
2 9
7 4
2 8
 4 0
 1 0

1
 0
 43
 0
 8
 0
 84
 82
 63
 166666166667000000
 21
 30
 292
 64
 36
 0
 84
 284
 1
 37
 1
 4
 59
 50
 1
 2
 120
 28
 4
 0

#include <bits/stdc++.h>
using namespace std;
int n;
int x, y, c, m;
vector<vector<pair<int, int> > > g;
vector<vector<pair<int, int> > > times;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    q;
vector<int> d;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
void findpath() {
  q.push(make_pair((1), (0)));
  d[1] = 0;
  while (!q.empty()) {
    pair<int, int> t = q.top();
    q.pop();
    if (t.second < d[t.first]) continue;
    for (vector<pair<int, int> >::iterator it = g[t.first].begin();
         it != g[t.first].end(); it++) {
      if (d[it->first] > t.second + it->second) {
        int prev = d[it->first];
        d[it->first] = t.second + it->second;
        vector<pair<int, int> >::iterator low =
            lower_bound((times[it->first]).begin(), (times[it->first]).end(),
                        make_pair((d[it->first]), (0)));
        if (low != times[it->first].end() && low->first == d[it->first]) {
          vector<pair<int, int> >::iterator up =
              upper_bound((times[it->first]).begin(), (times[it->first]).end(),
                          make_pair((d[it->first]), (0)));
          if (up != times[it->first].end()) {
            int group = up->second;
            vector<pair<int, int> >::iterator pos = lower_bound(
                (times[it->first]).begin(), (times[it->first]).end(),
                make_pair((0), (group + 1)), cmp);
            if (pos != times[it->first].end()) {
              pos--;
              d[it->first] = pos->first + 1;
            } else {
              if (!times[it->first].empty())
                d[it->first] = times[it->first].back().first + 1;
            }
          } else {
            d[it->first] = low->first + 1;
          }
        }
        if (prev < d[it->first])
          d[it->first] = prev;
        else
          q.push(make_pair((it->first), (d[it->first])));
      }
    }
  }
}
int main() {
  cin >> n >> m;
  g.assign(n + 1, vector<pair<int, int> >());
  times.assign(n + 1, vector<pair<int, int> >());
  d.assign(n + 1, 1000000000);
  for (int(i) = (1); (i) <= (m); ++(i)) {
    cin >> x >> y >> c;
    g[x].push_back(make_pair((y), (c)));
    g[y].push_back(make_pair((x), (c)));
  }
  for (int(i) = (1); (i) <= (n); ++(i)) {
    cin >> x;
    int q = 1;
    for (int(j) = (1); (j) <= (x); ++(j)) {
      cin >> y;
      if (!times[i].empty())
        if (times[i].back().first + 1 != y) {
          q++;
        }
      times[i].push_back(make_pair((y), (q)));
    }
  }
  findpath();
  if (d[n] == 1000000000)
    cout << "-1";
  else
    cout << d[n] << endl;
  return 0;
}
