#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <set>
#include <queue>
#include <stack>

using namespace std;
int N,M;
int head[11000];
struct Edge
{
	int from;
	int to;
	int len;
	int cost;
	int nex;
}edge[50000];
int cnt=0;
queue<int>q;
bool vis[10100];
int dis[10100];
int pre[10100];
int sum;
struct Node
{
	int x,y,val;
}node[30010];
int father[10100];
int cost[10100];
void ini()
{
	for(int i=0;i<=N;i++)
		father[i]=i;
}

int find(int x)
{
	return x==father[x]? x:father[x]=find(father[x]);
}

bool cmp(Node a,Node b)
{
	return a.val<b.val;
}
void add(int from,int to,int len,int cost)
{
	edge[cnt].from=from;
	edge[cnt].to=to;
	edge[cnt].len=len;
	edge[cnt].cost=cost;
	edge[cnt].nex=head[from];
	head[from]=cnt++;
		

	edge[cnt].from=to;
	edge[cnt].to=from;
	edge[cnt].len=len;
	edge[cnt].cost=cost;
	edge[cnt].nex=head[to];
	head[to]=cnt++;
}
void spfa1(int s)
{
	while(!q.empty())
		q.pop();
	memset(vis,0,sizeof(vis));
	memset(dis,0x7f,sizeof(dis));
	vis[s]=1;
	dis[s]=0;
	q.push(s);
	while(!q.empty())
		{
			int p=q.front();
			q.pop();
			for(int i=head[p];i!=-1;i=edge[i].nex)
				{
					int to=edge[i].to;
					int len=edge[i].len;
 					if(dis[to]>dis[p]+len)
						{
						dis[to]=dis[p]+len;
						if(!vis[to])
							{
							vis[to]=1;
							q.push(to);
							}
						}
				
				}
		vis[p]=0;
	}
}

void spfa(int s)
{
	while(!q.empty())
		{
		q.pop();
		}
	vis[s]=1;
	q.push(s);
	
	memset(cost,0x7f,sizeof(cost));
	cost[s]=0;
	while(!q.empty())
		{
			int p=q.front();
			q.pop();
			for(int i=head[p];i!=-1;i=edge[i].nex)
				{
					int to=edge[i].to;
					int len=edge[i].len;
					if(dis[to]==dis[p]+len)
						{
							cost[to]=min(edge[i].cost,cost[to]);
							q.push(to);
						}
				}
		}
return;
}
int main()
{
	while(scanf("%d%d",&N,&M)!=EOF)
		{
		if(N==0&&M==0)
			break;

		memset(head,0xffff,sizeof(head));
		for(int i=0;i<M;i++)
			{
			int from;
			int to;
			int len;
			int cost;
			scanf("%d%d%d%d",&from,&to,&len,&cost);
			add(from,to,len,cost);
			}
		spfa1(1);
		spfa(1);
		sum=0;
		for(int i=1;i<=N;i++)
			sum+=cost[i];
	
		printf("%d\n",sum);
		}

    return 0 ;
}