#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define pb push_back
#define mem(a) memset(a,1,sizeof(a))
typedef long long ll;
typedef pair<int,int> pii;

const int mn=1e4+5;

struct edge{
	int to,dist,cost;

};
vector<edge> g[mn];

struct node {
    int id,dist,cost;
    bool operator < (const node &p) const{
		return dist==p.dist?cost>p.cost:dist>p.dist;
	}
};

int n,m;

int d[mn];
int c[mn];
int sum=0;
void dijk(){
    priority_queue<node> q;
    for(int i=1;i<=n;i++) d[i]=1e9+7,c[i]=1e9+7;
    q.push(node{1,d[1]=0,c[1]=0});
    while(!q.empty()){
        node u=q.top();q.pop();
        if (d[u.id]<u.dist||c[u.id]<u.cost) continue;
        //printf("%d %d %d\n",u.id,u.dist,u.cost);
        sum+=u.cost;
        for(edge &e:g[u.id]){
            int t=e.dist+u.dist;
            if (d[e.to]>t||(d[e.to]==t&&c[e.to]>e.cost)){
                q.push(node{e.to,d[e.to]=t,c[e.to]=e.cost});
            }
        }
    }
}

int main() {
	while(~scanf("%d%d",&n,&m)&&n){
		sum=0;
		for(int i=1;i<=n;i++) g[i].clear();
        for(int i=1;i<=m;i++){
			int u,v,d,w;
			scanf("%d%d%d%d",&u,&v,&d,&w);
			g[u].pb(edge{v,d,w});
			g[v].pb(edge{u,d,w});
        }
        dijk();
        printf("%d\n",sum);
	}
	return 0;
}

