// Slower C++ solution:
/*************************************************************************

	> File Name: roadconstruction.cpp

	> Author: 

	> Mail: 

	> Created Time: Mon 09 Jul 2018 11:08:56 AM CST

 ************************************************************************/



#include<cstdio>

#include<vector>

#include<queue>

#include<cstring>

#include<algorithm>

using namespace std;



const int INF = 1e9;



struct edge{

    int to,value,cost;

    edge(){}

    edge(int a,int b,int c):to(a),value(b),cost(c){}

};



typedef pair<int,int> P;

vector<vector<edge> > G(20001);

int d[20001];

int dc[20001];

int V,E;

int sum = 0;



void dijkstra(int s){

    priority_queue<P, vector<P>, greater<P> > que;

    fill(d,d+20001,INF);

    fill(dc,dc+20001,INF);

    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.value){

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

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

                dc[e.to] = e.cost; 

            }

            else if(d[e.to]==d[v]+e.value){

                dc[e.to] = min(dc[e.to],e.cost);

            }

        }

    }

}



int main(){

    while(scanf("%d%d",&V,&E)!=-1){

        if(V==0&&E==0)break;

        for(int i=0;i<20001;i++)G[i].clear();

        sum = 0;

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

            int a,b,c,d;

            scanf("%d%d%d%d",&a,&b,&c,&d);

            a--;

            b--;

            G[a].push_back(edge(b,c,d));

            G[b].push_back(edge(a,c,d));

        }

        dijkstra(0);

        for(int i=1;i<V;i++)sum+=dc[i];

        printf("%d\n",sum);

    }

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 1.3000140056106047x):
#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;

}