#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const double EPS = 1e-9;
template <typename T>
T abs(const T& a) {
  if (a >= 0) return a;
  return -a;
}
template <typename T>
T sqr(T a, T b = 0) {
  return a * a + b * b;
};
inline int cmp(double a, double b = 0) {
  if (fabs(a - b) <= EPS) return 0;
  if (a < b) return -1;
  return 1;
}
int N, M;
vector<pair<int, int> > g[100010];
vector<int> times[100010];
long long d[100010];
long long dijkstra() {
  for (int i = 1; i < N; ++i) {
    d[i] = LINF;
  }
  d[0] = 0;
  priority_queue<pair<long long, int> > pq;
  pq.push(make_pair(0, 0));
  vector<int>::iterator it;
  int u, v, e;
  long long c;
  while (!pq.empty()) {
    u = pq.top().second;
    c = -pq.top().first;
    pq.pop();
    if (u == N - 1) break;
    if (d[u] < c) continue;
    it = lower_bound(times[u].begin(), times[u].end(), c);
    while (it != times[u].end() && c == *it) {
      ++c;
      ++it;
    }
    for (int i = 0; i < (int)g[u].size(); ++i) {
      v = g[u][i].first;
      e = g[u][i].second;
      if (d[v] > c + e) {
        d[v] = c + e;
        pq.push(make_pair(-(c + e), v));
      }
    }
  }
  if (d[N - 1] != LINF) return d[N - 1];
  return -1;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> M;
  int a, b, c;
  for (int i = 0; i < M; ++i) {
    cin >> a >> b >> c;
    --a;
    --b;
    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }
  for (int i = 0; i < N; ++i) {
    cin >> a;
    for (int j = 0; j < a; ++j) {
      cin >> b;
      times[i].push_back(b);
    }
  }
  long long ans = dijkstra();
  cout << ans << '\n';
  return 0;
}
