#include<iostream>
using namespace std;
#define Size 102
int INF = 0x7FFFFFFF;
int M,N;
//int P[Size]; //price
int L[Size]; //level
int dis[Size][Size];
int dist[Size];
int prev[Size];
int maxLevel = 0;
int minLevel = INF;
int minPrice = INF;
void Input()
{
cin >> M >> N;
for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++){
dis[i][j] = INF;
}
}
dis[0][0] = 0; //easy to forget!!!! important!
for(int i=1;i<=N;i++)
{
int tnum;
//cin >> P[i] >> L[i] >> tnum;
cin >> dis[0][i] >> L[i] >> tnum;
if(L[i] > maxLevel) maxLevel = L[i];
if(L[i] < minLevel) minLevel = L[i];
for(int j=1;j<=tnum;j++)
{
int tid;
cin >> tid;
cin >> dis[tid][i];
}
}
}
void printarray()
{
for(int i=0;i<N+1;i++){
for(int j=0;j<N+1;j++){
// printf("%12d",dis[i][j]);
}
// printf("\n");
}
}
int Dijkstra(int adventurerlevel,int leveldislimit,int *level, int source, int n, int *dist, int *prev, int dis[Size][Size])
//totally n dots! 0,1,2...n-1
{
//bool *exist = new bool [n];
bool exist[Size];
for(int i=0;i<n;i++)
{
dist[i] = INF;
exist[i] = 0;
}
dist[source] = 0;
int tmin = INF;
int tnode;
for(int j=0;j<n;j++){
tmin = INF;
for(int i=0;i<n;i++){
if(!exist[i] && dist[i]<tmin){
tmin = dist[i];
tnode = i;
//cout<<"t "<<tmin<<endl;
//cout<<tnode<<endl;
}
}
exist[tnode] = true;
if(tmin == INF) break;
//cout<<"tnode "<<tnode<<" le "<<level[tnode]<<endl;
if(tnode!=0)
if(adventurerlevel+leveldislimit<level[tnode]||adventurerlevel>level[tnode])
{
//important!!! if at current level not visitable!
//a higher level point may have already been reached from a lower point and dist value changed!
//so remove it!
dist[tnode] = INF;
continue;
}
//if(adventurerlevel>level[tnode]){
//continue;
//}
for(int i=0;i<n;i++){
if(!exist[i]){
int tdis = dist[tnode]+dis[tnode][i];
if(tdis<0) tdis=INF;
if(tdis < dist[i]){
dist[i] = tdis;
prev[i] = tnode;
}
}
}
}
//delete exist;
return dist[1];
}
void Solve()
{
minPrice = dis[0][1];
int alevel = 1;
for(int alevel=minLevel;alevel<=maxLevel;alevel++){
int p = Dijkstra(alevel, M, L, 0, N+1, dist, prev, dis); //totally n dots! 0,1,2...n-1
//cout<<"level "<<alevel<<" "<<endl;
if(p<minPrice) minPrice = p;
}
}
void Output()
{
cout << minPrice << endl;
}
int main(){
Input();
//printarray();
Solve();
Output();
return 0;
}
using namespace std;
#define Size 102
int INF = 0x7FFFFFFF;
int M,N;
//int P[Size]; //price
int L[Size]; //level
int dis[Size][Size];
int dist[Size];
int prev[Size];
int maxLevel = 0;
int minLevel = INF;
int minPrice = INF;
void Input()
{
cin >> M >> N;
for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++){
dis[i][j] = INF;
}
}
dis[0][0] = 0; //easy to forget!!!! important!
for(int i=1;i<=N;i++)
{
int tnum;
//cin >> P[i] >> L[i] >> tnum;
cin >> dis[0][i] >> L[i] >> tnum;
if(L[i] > maxLevel) maxLevel = L[i];
if(L[i] < minLevel) minLevel = L[i];
for(int j=1;j<=tnum;j++)
{
int tid;
cin >> tid;
cin >> dis[tid][i];
}
}
}
void printarray()
{
for(int i=0;i<N+1;i++){
for(int j=0;j<N+1;j++){
// printf("%12d",dis[i][j]);
}
// printf("\n");
}
}
int Dijkstra(int adventurerlevel,int leveldislimit,int *level, int source, int n, int *dist, int *prev, int dis[Size][Size])
//totally n dots! 0,1,2...n-1
{
//bool *exist = new bool [n];
bool exist[Size];
for(int i=0;i<n;i++)
{
dist[i] = INF;
exist[i] = 0;
}
dist[source] = 0;
int tmin = INF;
int tnode;
for(int j=0;j<n;j++){
tmin = INF;
for(int i=0;i<n;i++){
if(!exist[i] && dist[i]<tmin){
tmin = dist[i];
tnode = i;
//cout<<"t "<<tmin<<endl;
//cout<<tnode<<endl;
}
}
exist[tnode] = true;
if(tmin == INF) break;
//cout<<"tnode "<<tnode<<" le "<<level[tnode]<<endl;
if(tnode!=0)
if(adventurerlevel+leveldislimit<level[tnode]||adventurerlevel>level[tnode])
{
//important!!! if at current level not visitable!
//a higher level point may have already been reached from a lower point and dist value changed!
//so remove it!
dist[tnode] = INF;
continue;
}
//if(adventurerlevel>level[tnode]){
//continue;
//}
for(int i=0;i<n;i++){
if(!exist[i]){
int tdis = dist[tnode]+dis[tnode][i];
if(tdis<0) tdis=INF;
if(tdis < dist[i]){
dist[i] = tdis;
prev[i] = tnode;
}
}
}
}
//delete exist;
return dist[1];
}
void Solve()
{
minPrice = dis[0][1];
int alevel = 1;
for(int alevel=minLevel;alevel<=maxLevel;alevel++){
int p = Dijkstra(alevel, M, L, 0, N+1, dist, prev, dis); //totally n dots! 0,1,2...n-1
//cout<<"level "<<alevel<<" "<<endl;
if(p<minPrice) minPrice = p;
}
}
void Output()
{
cout << minPrice << endl;
}
int main(){
Input();
//printarray();
Solve();
Output();
return 0;
}