#include #include #include #include using namespace std; using ll=long long; using ull=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) template using nega_queue = priority_queue,greater>; const ll INF = 1001001001001001001; struct Edge{ int to; ll d; }; int N,M; vector> E; vector D; int main(){ scanf("%d%d",&N,&M); E.resize(N+M); rep(i,M){ int k,c; scanf("%d%d",&k,&c); rep(kk,k){ int s; scanf("%d",&s); E[s-1].push_back({N+i,s+c}); E[N+i].push_back({s-1,s+c}); } } D.assign(N+M,INF); nega_queue> Q; D[0]=0; Q.push({0,0}); while(Q.size()){ ll d = Q.top().first; int p = Q.top().second; Q.pop(); if(D[p]!=d) continue; for(auto e : E[p]){ ll nxd = D[p] + e.d; if(e.to