//YPZ_YPZ_YPZ_YPZ_YPZ
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<set>
#include<queue>

#define ll long long
#define RG register
#define il inline
#define inf 1073741824
#define rep(i,a,b) for(register int i=a;i<=b;++i)
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std;
const int N=10010,M=20010;
struct Edge{
	int to,net,w,c;
}e[M*2];
int head[N],num_e,n,m;

il void add(int x,int y,int w,int c){
	e[++num_e].to=y,e[num_e].w=w,e[num_e].c=c,e[num_e].net=head[x],head[x]=num_e;
}

il int gi() {
  RG int res=0,f=1;RG char ch=getchar();while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
  if(ch=='-')f=-1,ch=getchar();while(ch>='0'&&ch<='9') res=res*10+ch-'0',ch=getchar();
  return res*f;
}

int dis[N],p[N],C;
bool inq[N];

il void spfa(int s){
	rep(i,1,n) dis[i]=inf;
	dis[s]=0; queue<int> q;q.push(s);RG int u;
	while(!q.empty()){
		u=q.front(); q.pop(); inq[u]=0;
		for(int i=head[u];i!=-1;i=e[i].net){
			int to=e[i].to;
			if(dis[to]>=dis[u]+e[i].w){
				if(dis[to]>dis[u]+e[i].w){
					dis[to]=dis[u]+e[i].w;
					if(p[to]!=-1) C-=e[p[to]].c;
					C+=e[i].c;
					p[to]=i;
					if(!inq[to]) q.push(to),inq[to]=1;
				}
				else if(dis[to]==dis[u]+e[i].w){
					if(e[p[to]].c > e[i].c){
						C=C-e[p[to]].c+e[i].c;
						p[to]=i;
					}
				}
			}
		}
	}
}

int main(){
	while(scanf("%d%d",&n,&m)!=EOF){
		if(!n&&!m)break; RG int u,v,w,c;
		memset(head,-1,sizeof(head)),num_e=-1;
		memset(p,-1,sizeof(p)); C=0;
		rep(i,1,m) u=gi(),v=gi(),w=gi(),c=gi(),add(u,v,w,c),add(v,u,w,c);
		spfa(1);
		printf("%d\n",C);
	}
  return 0;
}