#include<bits/stdc++.h>
using namespace std;
#define int long long
namespace IO{
char ibuf[(1<<20)+1],*iS,*iT;
#if ONLINE_JUDGE
#define gh() (iS==iT?iT=(iS=ibuf)+fread(ibuf,1,(1<<20)+1,stdin),(iS==iT?EOF:*iS++):*iS++)
#else
#define gh() getchar()
#endif
inline long long read(){
char ch=gh();
long long x=0;
bool t=0;
while(ch<'0'||ch>'9') t|=ch=='-',ch=gh();
while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();
return t?-x:x;
}
}
using namespace IO;
struct xy
{
int x,y,z;
}te,te1;
bool operator <(xy x,xy y)
{
return x.y<y.y;
}
vector<xy> g[7010];
vector<int> c[7010];
priority_queue<xy> q;
int dis[7010],w[7010],t1,t2,t3,n,m,f[7010];
bool b[7010],u[7010];
signed main()
{
memset(dis,0x3f3f3f3f,sizeof dis);
memset(u,0,sizeof u);
n=read();m=read();
for(int i=1;i<=m;++i)
{
t1=read();
t2=read();
t3=read();
g[t1].push_back({t1,t2,t3});
}
for(int i=1;i<=n;++i)
{
t1=read();
w[i]=t1;
for(int j=1;j<=t1;++j)
{
t2=read();
c[t2].push_back(i);
}
}
te={1,0,0};
dis[1]=0;
q.push(te);
while(!q.empty())
{
te=q.top();
q.pop();
if(u[te.x]==1)continue;
u[te.x]=1;
for(auto i:g[te.x])
{
if(te.y+i.z<dis[i.y])
{
te1.x=i.y;
te1.y=te.y+i.z;
dis[te1.x]=te1.y;
if(w[te1.x]==0)q.push(te1);
}
}
if(!b[te.x])
{
b[te.x]=1;
for(auto j:c[te.x])
{
w[j]--;
if(w[j]==0)
{
if(dis[j]<te.y)dis[j]=te.y;
q.push({j,dis[j],0});
}
}
}
}
printf("%lld",dis[n]);
return 0;
}