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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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
 
using namespace std;
 
#define endl '\n'
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
 
typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;
#define mp make_pair
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define X first
#define Y second
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
 
//use to find kth smallest element in int set, insert with ob.insert(int), find rank with *ob.find_by_order(k-1)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;  
 
template<typename T>
void print(T ar[], int n)
{
    for (int i = 0; i < n; i++)
    {
        cout << ar[i] << " ";
    }
    cout << endl;
}
 
template<typename T>
void print(vector<T> &vec)
{
    for (int i = 0; i < vec.size(); i++)
    {
        cout << vec[i] << " ";
    }
    cout << endl;
}
 
void do_stuff()
{
    int n, m;
    cin >> n >> m;
 
    bool included[n + 1];
    int parent[n + 1];
    ll cost[n + 1];
    vector<list<pair<int, ll>>> graph(n + 1);
    for (int i = 0; i <= n; i++)
    {
        included[i] = false;
        parent[i] = 0;
        cost[i] = pow(10, 14);
    }
    for (int i = 1; i <= m; i++)
    {
        int u, v;
        ll c;
        cin >> u >> v >> c;
        graph[u].push_back(make_pair(v, c));
        graph[v].push_back(make_pair(u, c));
        // edge_to_cost[make_pair(u, v)] = c;
        // edge_to_cost[make_pair(v, u)] = c;
    }
 
    vector<vector<ll>> times(n + 1);
    for (int i = 1; i <= n; i++)
    {
        int k;
        cin >> k;
        times[i] = vector<ll>(k);
        forn(j, k)
        {
            cin >> times[i][j];
        }
    }
 
    int s, f;
    s = 1, f = n;
    cost[s] = 0;
   
    auto it = find(times[s].begin(), times[s].end(), 0);
    while (it != times[s].end())
    {
        if (cost[s] == *it)
        {
            cost[s]++;
            it++;
        }
        else
        {
            break;
        }
    }
    parent[s] = s;
    set<pair<ll, int>> not_inluded_set;
    for (int i = 1; i <= n; i++)
    {
        not_inluded_set.insert(make_pair(cost[i], i));
    }
 
    while (!not_inluded_set.empty())
    {
        auto m = *not_inluded_set.begin();
        if(m.first== (ll)pow(10,14))
        {
            break;
        }
        not_inluded_set.erase(not_inluded_set.begin());
        included[m.second] = true;
        if (m.second == f)
        {
            break;
        }
 
        ll overhead = 0;
        auto it = find(times[m.second].begin(), times[m.second].end(), m.first);
        while(it!=times[m.second].end())
        {
            if(m.first+overhead==*it)
            {
                overhead++;
                it++;
            }
            else
            {
                break;
            }
        }
 
        for (auto i : graph[m.second])
        {
            if (!included[i.first])
            {
                if (cost[m.second] + i.second +overhead< cost[i.first])
                {
                    auto temp = not_inluded_set.find(make_pair(cost[i.first], i.first));
 
                    not_inluded_set.erase(temp);
                    cost[i.first] = cost[m.second] + i.second+ overhead;
                    parent[i.first] = m.second;
                    not_inluded_set.insert(make_pair(cost[i.first], i.first));
                }
            }
        }
    }
 
    
    if(cost[f]==(ll)pow(10,14))
    {
        cout << -1 << endl;
    }
    else
    {
        cout << cost[f] << endl;   
    }
    
    
}
 
int main()
{
    fast_io
    
    int t;
    //cin >> t;
 
    t=1;
    while (t--)
    {
        do_stuff();
    }
}