#include<stdio.h>
#include<string.h>
#define min(x,y) ((x<y)?x:y)
int r[10005][10005];
int e[10005][10005];
int v[10005],used[10005],prev[10005],con[10005];
int main(){
	int n,m,i,j,a,b,d,c,x,y,s1,s2;
	while(1){
		scanf("%d%d",&n,&m);
		if(n==0 && m==0)break;
		for(i=1;i<=n;i++){
			v[i]=con[i]=10000;
			used[i]=0;prev[i]=-1;
			for(j=1;j<=n;j++)r[i][j]=e[i][j]=10000;
		}
		s1=s2=0;
		for(i=0;i<m;i++){
			scanf("%d%d%d%d",&a,&b,&d,&c);
			r[a][b]=r[b][a]=d;
			e[a][b]=e[b][a]=c;
			s1+=c;
		}
		v[1]=0;con[1]=0;
		while(1){
			x=-1;
			for(i=1;i<=n;i++){
				if(used[i]==0 && (x==-1 || v[i]<v[x]))x=i;
			}
			if(x==-1)break;
			used[x]=1;
			for(i=1;i<=n;i++){
				//v[i]=min(v[i],v[x]+r[x][i]);
				if(v[x]+r[x][i]<v[i]){
					v[i]=v[x]+r[x][i];
					con[i]=con[x]+e[x][i];
					prev[i]=x;
				}else if(v[x]+r[x][i]==v[i]){
					if(e[x][i]<con[i]-con[prev[i]]){
						con[i]=con[x]+e[x][i];
						prev[i]=x;
					}
				}
			}
			//printf("v[%d]:%d\n",x,v[x]);
		}
		for(i=1;i<=n;i++){
			if(prev[i]>0 && r[prev[i]][i]<=1000){
				s2+=e[prev[i]][i];
				r[prev[i]][i]=10000;
			}
		}
		printf("%d\n",s2);
	}
	return 0;
}