#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > e[101000];
vector<pair<int, int> > idle[101000];
int d[101000];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    a--;
    b--;
    e[a].push_back(make_pair(b, c));
    e[b].push_back(make_pair(a, c));
  }
  for (int i = 1; i < n; i++) d[i] = 1234567890;
  for (int i = 0; i < n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      int q;
      scanf("%d", &q);
      idle[i].push_back(make_pair(q, -1));
    }
    for (int j = idle[i].size() - 1; j >= 0; j--) {
      if (j + 1 == idle[i].size()) {
        idle[i][j].second = idle[i][j].first + 1;
      } else if (j + 1 < idle[i].size() &&
                 idle[i][j].first + 1 < idle[i][j + 1].first) {
        idle[i][j].second = idle[i][j].first + 1;
      } else {
        idle[i][j].second = idle[i][j + 1].second;
      }
    }
  }
  set<pair<int, int> > st;
  for (int i = 0; i < n; i++) {
    st.insert(make_pair(d[i], i));
  }
  for (int i = 0; i < n; i++) {
    if (st.size() == 0) break;
    int from = (*st.begin()).second;
    int val = (*st.begin()).first;
    st.erase(st.begin());
    int s = 0;
    int et = idle[from].size() - 1;
    while (s <= et) {
      int m = (s + et) / 2;
      if (idle[from][m].first < val)
        s = m + 1;
      else if (idle[from][m].first > val)
        et = m - 1;
      else {
        val = idle[from][m].second;
        break;
      }
    }
    for (int j = 0; j < e[from].size(); j++) {
      if (val + e[from][j].second < d[e[from][j].first]) {
        st.erase(make_pair(d[e[from][j].first], e[from][j].first));
        d[e[from][j].first] = val + e[from][j].second;
        st.insert(make_pair(d[e[from][j].first], e[from][j].first));
      }
    }
  }
  if (d[n - 1] == 1234567890) {
    printf("-1\n");
    return 0;
  }
  printf("%d\n", d[n - 1]);
}
