// 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.4502439706374788x):
#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))// 水印 



struct node{

	int to,next,dis,cost;

}edge[40100];

int head[10100];

int dis[10100],cost[10100];

bool vst[10100];

int n,m,k;



void spfa(int x)

{

	clean(dis,INF);

	clean(cost,INF);

	clean(vst,0);

	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;

			}

		}

	}

}



void add(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++;

}



int main()

{

	while(cin>>n>>m&&n!=0||m!=0)

	{

		clean(head,-1);

		k=0;

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

		{

			int a,b,d,c;

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

			add(a,b,d,c);

			add(b,a,d,c);

		}

		spfa(1);

		ll res=0;

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

			res=res+cost[i];

		cout<<res<<endl;

	}

}