// Slower C++ solution:
/*************************************************************************

	> File Name: roadconstruction.cpp

	> Author: 

	> Mail: 

	> Created Time: Mon 09 Jul 2018 11:08:56 AM CST

 ************************************************************************/



#include<cstdio>

#include<vector>

#include<queue>

#include<cstring>

#include<algorithm>

using namespace std;



const int INF = 1e9;



struct edge{

    int to,value,cost;

    edge(){}

    edge(int a,int b,int c):to(a),value(b),cost(c){}

};



typedef pair<int,int> P;

vector<vector<edge> > G(20001);

int d[20001];

int dc[20001];

int V,E;

int sum = 0;



void dijkstra(int s){

    priority_queue<P, vector<P>, greater<P> > que;

    fill(d,d+20001,INF);

    fill(dc,dc+20001,INF);

    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.value){

                d[e.to] = d[v] + e.value;

                que.push(P(d[e.to],e.to));

                dc[e.to] = e.cost; 

            }

            else if(d[e.to]==d[v]+e.value){

                dc[e.to] = min(dc[e.to],e.cost);

            }

        }

    }

}



int main(){

    while(scanf("%d%d",&V,&E)!=-1){

        if(V==0&&E==0)break;

        for(int i=0;i<20001;i++)G[i].clear();

        sum = 0;

        for(int i=0;i<E;i++){

            int a,b,c,d;

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

            a--;

            b--;

            G[a].push_back(edge(b,c,d));

            G[b].push_back(edge(a,c,d));

        }

        dijkstra(0);

        for(int i=1;i<V;i++)sum+=dc[i];

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

    }

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 1.2457664291416355x):
#include <iostream>

#include <cstdio>

#include <algorithm>

#include <cmath>

#include <deque>

#include <vector>

#include <queue>

#include <string>

#include <cstring>

#include <map>

#include <stack>

#include <set>

using namespace std;

typedef long long ll;

const int inf=0x3f3f3f3f;

const int INF=2147483647;

const double pi=3.1415926535897932384626;

inline ll read(){

	ll x=0,f=1;

	char ch=getchar();

	while(ch<'0'||ch>'9'){

		if(ch=='-') f=-1;

		ch=getchar();

	}

	while(ch>='0'&&ch<='9'){

		x=(x<<1)+(x<<3)+(ch^48);

		ch=getchar();

	}

	return x*f;

}

const int maxn=1e4+5;

int n,m,u,v,dd,cc,ans,d[maxn],c[maxn],vis[maxn];

struct edge{

	int to,dis,cost;

};

vector<edge> g[maxn];

void Dijkstra(){

	memset(vis,0,sizeof(vis));

	memset(d,inf,sizeof(d));

	memset(c,inf,sizeof(c));

	d[1]=0;

	c[1]=0;

	ans=0;

	while(1){

		int v=-1;

		for(int u=1;u<=n;u++){

			if(!vis[u]&&(v==-1||d[u]<d[v])) v=u;

		}

		if(v==-1) break;

		vis[v]=1;

		ans+=c[v];

		for(int i=0;i<g[v].size();i++){

			int u=g[v][i].to,dis=g[v][i].dis,cost=g[v][i].cost;

			if(d[u]>d[v]+dis||(d[u]==d[v]+dis&&cost<c[u])){

				d[u]=d[v]+dis;

				c[u]=cost;

			}

		}

	}

}

int main(){

	while(~scanf("%d%d",&n,&m)&&(n+m)){

		for(int i=1;i<=n;i++) g[i].clear();

		for(int i=1;i<=m;i++){

			u=read(),v=read(),dd=read(),cc=read();

			g[u].push_back({v,dd,cc});

			g[v].push_back({u,dd,cc});

		}

		Dijkstra();

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

	}

	return 0;

}