// Slower C++ solution:
#include "cstring"

#include "cstdio"

#include "vector"

#include "queue"

using namespace std;



const int maxn=11000;



struct edge{int to,d,c;};

edge edges[4100000];

int p;



vector<int>g[maxn];



int dis[maxn],vis[maxn],cos[maxn];

int n,m,sn;



void add(int u,int v,int d,int c)

{

	edges[++p].d=d;

	edges[p].to=v;

	edges[p].c=c;

	g[u].push_back(p);

}



int spfa(int s)

{

	memset(cos,0x3f3f3f3f,sizeof(cos));

	memset(dis,0x3f3f3f3f,sizeof(dis));

	memset(vis,0,sizeof(vis));

	

	queue<int>qn;

	qn.push(s);

	dis[s]=0;

	cos[s]=0;

	vis[s]=1;

	

	while(!qn.empty())

	{

		int nn=qn.front();qn.pop();

		vis[nn]=0;

		for(int i=0,d=g[nn].size();i<d;i++)

		{

			edge &e= edges[g[nn][i]];

			if(dis[e.to]>dis[nn]+e.d || ((dis[e.to]==dis[nn]+e.d) && cos[e.to]>e.c))

			{

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

				cos[e.to]=e.c;

				

				if(!vis[e.to])

				{

					qn.push(e.to);

					vis[e.to]=1;

				}

			}

		}	

	}

	return 0;

}



int main()

{

	//freopen("q.txt","r",stdin);

	int u,v,d,c;

	while(~scanf("%d%d",&n,&m))

	{

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

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

			g[i].clear();

		p=0;

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

		{

			scanf("%d%d%d%d",&u,&v,&d,&c);

			add(u,v,d,c);

			add(v,u,d,c);

		}

		int ans=0;

		spfa(1);

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

			ans+=cos[i];

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

	}

	return 0;

} 


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

}