#include <bits/stdc++.h>
using namespace std;
inline long long gcd(long long a, long long b) {
  while (b != 0) {
    long long c = a % b;
    a = b;
    b = c;
  }
  return a < 0 ? -a : a;
}
inline long long lowbit(long long x) { return x & (-x); }
const double PI = 3.14159265358979323846;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1e9 + 7;
inline long long rd() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const double eps = 1e-6;
const int M = 1e6 + 10;
const int N = 1e6 + 10;
bool vis[N];
long long dis[N];
vector<int> ver[N];
vector<int> use[N];
struct Edge {
  int to, next, w;
} e[N << 1];
int head[N], tot;
void add(int x, int y, int z) {
  e[++tot] = {
      y,
      head[x],
      z,
  };
  head[x] = tot;
}
struct MM {
  int node;
  long long d;
  bool friend operator<(const MM& m1, const MM& m2) { return m1.d > m2.d; }
};
priority_queue<MM> q;
int check(int x, int y) {
  int p = lower_bound(ver[x].begin(), ver[x].end(), y) - ver[x].begin();
  if (p == ver[x].size() || ver[x][p] != y) return y;
  return use[x][p];
}
int n, m;
long long dijkstra(int u) {
  dis[u] = check(u, 0);
  q.push({u, dis[u]});
  while (q.size()) {
    int x = q.top().node;
    q.pop();
    if (x == n) return dis[n];
    if (vis[x]) continue;
    vis[x] = 1;
    for (int i = head[x]; i != -1; i = e[i].next) {
      int y = e[i].to;
      long long dd = dis[x] + e[i].w;
      if (y != n) {
        dd = check(y, dd);
      }
      if (dd < dis[y]) {
        dis[y] = dd;
        q.push({y, dis[y]});
      }
    }
  }
  return -1;
}
void init() {
  memset(dis, INF, sizeof(long long) * (n + 10));
  memset(vis, 0, sizeof(bool) * (n + 10));
  memset(head, -1, sizeof(int) * (n + 10));
  tot = 0;
}
int main() {
  n = rd(), m = rd();
  init();
  while (m--) {
    int u = rd(), v = rd(), w = rd();
    add(u, v, w);
    add(v, u, w);
  }
  for (int i = 1; i <= n; i++) {
    int tmp = rd();
    while (tmp--) {
      ver[i].push_back(rd());
    }
  }
  for (int i = 1; i <= n; i++) {
    if (ver[i].size() == 0) continue;
    for (int j = ver[i].size() - 1; j >= 0; j--) {
      if (j == ver[i].size() - 1)
        use[i].push_back(ver[i][j] + 1);
      else {
        if (ver[i][j] == ver[i][j + 1] - 1)
          use[i].push_back(use[i].back());
        else
          use[i].push_back(ver[i][j] + 1);
      }
    }
    reverse(use[i].begin(), use[i].end());
  }
  cout << dijkstra(1) << endl;
}
