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

#include<cstdio>

#include<vector>

#include<cstring>

#include<iostream>

#include<algorithm>

#define RG register

#define LL long long

#define fre(a) freopen(a".in","r",stdin);//freopen(a".out","w",stdout);

using namespace std;

const int MAXN=50000;

int n,m,num;

int head[MAXN],to[MAXN],len[MAXN],cost[MAXN],Next[MAXN];

int dis[MAXN],pre[MAXN],pree[MAXN];

bool vis[MAXN],use[MAXN];

queue<int>que;

void add(int f,int t,int l,int c)

{

   Next[++num]=head[f];

   to[num]=t;

   len[num]=l;

   cost[num]=c;

   head[f]=num;

}

void SPFA()

{

   que.push(1);

   dis[1]=0;

   while(!que.empty())

      {

	 int now=que.front();

	 que.pop(); vis[now]=0;

	 for(int i=head[now];i;i=Next[i])

	    {

	       int son=to[i];

	       if(dis[now]+len[i]<dis[son])

		  {

		     dis[son]=dis[now]+len[i];

		     pre[son]=now;

		     pree[son]=i;

		     if(!vis[son])

			{

			   vis[son]=1;

			   que.push(son);

			}

		  }

	       else if(dis[now]+len[i]==dis[son])

		  {

		     if(cost[i]<cost[pree[son]])

			pree[son]=i,pre[son]=now;

		  }

	    }

      }

}

int main()

{

   //fre("1");

   while(1)

      {

	 scanf("%d%d",&n,&m);

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

	 num=0;

	 memset(head,0,sizeof head);

	 for(int i=1,a,b,c,d;i<=m;i++)

	    {

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

	       add(a,b,c,d); add(b,a,c,d);

	    }

	 memset(dis,0x3f3f3f3f,sizeof dis);

	 memset(vis,0,sizeof vis);

	 memset(use,0,sizeof use);

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

	 SPFA();

	 //for(int i=1;i<=n;i++)printf("dis[%d]=%d\n",i,dis[i]);printf("----------------\n");

	 int ans=0;

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

	    for(int j=i;j>1;j=pre[j])

	       if(!use[pree[j]])

		  ans+=cost[pree[j]],use[pree[j]]=1;

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

      }

   return 0;

}

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

}