// Slower C++ solution:
#include<iostream>

#include<queue>

#include<functional>

#include<cstring>



using namespace std;



#define maxn 10240 

#define INF 0x3f3f3f3f;



typedef struct edge{

	int to,dis,cos;

	edge(){}

	edge(int to,int dis,int cos):to(to),dis(dis),cos(cos){}

};

typedef pair<int ,int> P;



vector<edge>G[maxn];



int d[maxn];

int v;//定点



void dijkstra(int s){

	priority_queue<P,vector<P>,greater<P> > que;//优先输出小数据；

	memset(d,0x3f,sizeof(d));

	d[s]=0;

	que.push(P(0,s));

	while(!que.empty())

	{

		P p=que.top();

		que.pop();

		int v=p.second;

		if(d[v]<p.first)continue;

		for(int i=0;i<G[v].size();i++)

		{

			edge e=G[v][i];

			if(d[e.to]>d[v]+e.dis)

			{

				d[e.to]=d[v]+e.dis;

				que.push(P(d[e.to],e.to));

			}

		}

	}	

} 

int main()

{

	int m;

	while(cin>>v>>m)

	{

		if(v==0&&m==0)break;

		for(int i=0;i<v;i++)

		{

			G[i].clear();

		}

		for(int i=0;i<m;i++)

		{

			int u,v,d,c;

			cin>>u>>v>>d>>c;

			u--,v--;

			G[u].push_back(edge(v,d,c));

			G[v].push_back(edge(u,d,c)); 

		}

		dijkstra(0);

		int ans=0;

		for(int i=1;i<v;i++)

		{

			int min=INF;

			for (int j=0;j<G[i].size();j++)

			{

				if(d[G[i][j].to]+G[i][j].dis==d[i]&&G[i][j].cos<min)

				{

					min=G[i][j].cos;

				}

				

			} 

			ans+=min;

		}cout<<ans<<endl;

	}

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.1160750142830245x):
#include<stdio.h>

#include<string.h>  

#include<math.h>  

  

//#include<map>   

//#include<set>

#include<deque>  

#include<queue>  

#include<stack>  

#include<bitset> 

#include<string>  

#include<iostream>  

#include<algorithm>  

using namespace std;  

  

#define ll long long  

#define INF 0x3f3f3f3f  

#define mod 1000000

#define clean(a,b) memset(a,b,sizeof(a))// 水印 

//spfa

//https://cn.vjudge.net/contest/239171#problem/C 



using namespace std;

//const int maxn=10005;

const int inf=0x3f3f3f3f;

int N,M,k;

int head[10100],cost[10100],dis[10100];

bool vst[10100];

struct node{

    int to,next,dis,cost;

}edge[50100];

void addEdge(int a,int b,int dis,int cost)

{

    edge[k].to=b;

    edge[k].dis=dis;

    edge[k].cost=cost;

    edge[k].next=head[a];

    head[a]=k;

    k++;

}

void spfa(int x)

{

	clean(dis,INF);

	clean(vst,0);

	clean(cost,INF);

//    memset(dis,inf,sizeof(dis));

//    memset(vst,0,sizeof(vst));

//    memset(cost,inf,sizeof(cost));

    queue<int> q;

    dis[x]=0;

    cost[x]=0;

    q.push(x);

    while(!q.empty())

	{

        x=q.front();q.pop();

        vst[x]=0;

        for(int i=head[x];i!=-1;i=edge[i].next)

		{

            node b=edge[i];

            if(dis[b.to]>dis[x]+b.dis)

			{

                if(!vst[b.to])

				{

                    vst[b.to]=1;

                    q.push(b.to);

                }

                dis[b.to]=dis[x]+b.dis;

                cost[b.to]=b.cost;

            }

			else if(dis[b.to]==dis[x]+b.dis)

			{

                if(cost[b.to]>b.cost)

                    cost[b.to]=b.cost;

            }

        }

    }

}



int main()

{

    while(cin>>N>>M,N)

	{

        clean(head,-1);

        k=0;

        for(int i=0;i<M;i++){

            int a,b,d,c;

            cin>>a>>b>>d>>c;

            addEdge(a,b,d,c);

            addEdge(b,a,d,c);

        }

        spfa(1);

        long long re=0;

        for(int i=1;i<=N;i++){

            re+=cost[i];

        }

        cout<<re<<endl;

    }



    return 0;

}