// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e4+9;

const int inf = 0x3f3f3f3f;

typedef long long int ll;

typedef pair<int,int> pi;

struct {

    int v,nex,d,c;

}e[maxn*2];

int in[maxn];

int dis[maxn];

int head[maxn];

int tot;

void addedge(int u,int v,int d,int c){

    e[tot] ={v,head[u],d,c};

    head[u] = tot++;

}

int dd[maxn];

priority_queue<pi> qq;

int main()

{

    int n,m;

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

            tot =0;

        if(n==0 && m==0 ) break;

        memset(head,-1,sizeof(head));

        memset(dd,0x3f,sizeof(dd));

        memset(dis,0x3f,sizeof(dis));

        memset(in,0,sizeof(in));



        while(!qq.empty()){

            qq.pop();

        }

        qq.push(pi(0,1));

        dis[1] =0;

        dd[1] = 0;



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

            int u,v,d,c;

            scanf("%d%d%d%d",&u,&v,&d,&c);

            addedge(u,v,d,c);

            addedge(v,u,d,c);

        }

        while(!qq.empty()){

            pi now = qq.top();

            qq.pop();

            int pp = now.second;

            if(in[pp]==1) continue;

            in[pp] = 1;

            for(int i=head[pp];i!=-1;i=e[i].nex){

                int v= e[i].v;

                int d = e[i].d;

                if(in[v]==1) continue;

                if( dis[pp]+d<dis[v]){

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

                    dd[v] = e[i].c;

                    qq.push(pi(-dis[v],v));

                }else if(dis[pp]+d==dis[v]){

                    dd[v] = min(dd[v],e[i].c);

                }

            }

        }

        int ans = 0;

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

            ans+=dd[i];

        }

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

    }

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 1.1813645306457277x):
#include<stdio.h>

#include<string.h>  

#include<math.h>  

  

//#include<map>   

//#include<set>

#include<deque>  

#include<queue>  

#include<stack>  

#include<bitset> 

#include<string>  

#include<iostream>  

#include<algorithm>  

using namespace std;  

  

#define ll long long  

#define INF 0x3f3f3f3f  

#define mod 1000000

#define clean(a,b) memset(a,b,sizeof(a))// 水印 

//spfa

//https://cn.vjudge.net/contest/239171#problem/C 



using namespace std;

//const int maxn=10005;

const int inf=0x3f3f3f3f;

int N,M,k;

int head[10100],cost[10100],dis[10100];

bool vst[10100];

struct node{

    int to,next,dis,cost;

}edge[50100];

void addEdge(int a,int b,int dis,int cost)

{

    edge[k].to=b;

    edge[k].dis=dis;

    edge[k].cost=cost;

    edge[k].next=head[a];

    head[a]=k;

    k++;

}

void spfa(int x)

{

	clean(dis,INF);

	clean(vst,0);

	clean(cost,INF);

//    memset(dis,inf,sizeof(dis));

//    memset(vst,0,sizeof(vst));

//    memset(cost,inf,sizeof(cost));

    queue<int> q;

    dis[x]=0;

    cost[x]=0;

    q.push(x);

    while(!q.empty())

	{

        x=q.front();q.pop();

        vst[x]=0;

        for(int i=head[x];i!=-1;i=edge[i].next)

		{

            node b=edge[i];

            if(dis[b.to]>dis[x]+b.dis)

			{

                if(!vst[b.to])

				{

                    vst[b.to]=1;

                    q.push(b.to);

                }

                dis[b.to]=dis[x]+b.dis;

                cost[b.to]=b.cost;

            }

			else if(dis[b.to]==dis[x]+b.dis)

			{

                if(cost[b.to]>b.cost)

                    cost[b.to]=b.cost;

            }

        }

    }

}



int main()

{

    while(cin>>N>>M,N)

	{

        clean(head,-1);

        k=0;

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

            int a,b,d,c;

            cin>>a>>b>>d>>c;

            addEdge(a,b,d,c);

            addEdge(b,a,d,c);

        }

        spfa(1);

        long long re=0;

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

            re+=cost[i];

        }

        cout<<re<<endl;

    }



    return 0;

}