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

using namespace std;

struct node{

    int next,d,c;

};

const int maxn=10005;

int n,m;

int d[maxn],c[maxn];

bool vis[maxn];

void init()

{

    for(int i=0;i<maxn;i++)

        d[i]=c[i]=1e9,vis[i]=0;

}

int main()

{

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

    {

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

        init();vector<node> v[maxn];

        for(int i=0;i<m;i++)

        {

            int x,y,d,c;

            scanf("%d%d%d%d",&x,&y,&d,&c);

            v[x].push_back(node{y,d,c});

            v[y].push_back(node{x,d,c});

        }

        queue<int> q;

        q.push(1);

        d[1]=c[1]=0;vis[1]=1;

        while(!q.empty())

        {

            int u=q.front();q.pop();vis[u]=0;

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

            {

                int nx=v[u][i].next;

                if(d[nx]==d[u]+v[u][i].d&&c[nx]>v[u][i].c){

                        c[nx]=v[u][i].c;

                }

                if(d[nx]>d[u]+v[u][i].d)

                {

                    d[nx]=d[u]+v[u][i].d;

                    c[nx]=v[u][i].c;

                    if(vis[nx]) continue;

                    vis[nx]=1;

                    q.push(nx);

                }

            }

        }

        int ans=0;

        for(int i=2;i<=n;i++) ans+=c[i];

        cout<<ans<<endl;

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.250633009671746x):
#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;

}