// Slower C++ solution:
#include <iostream>

#include <string>

#include <queue>

#include <cstdio>

#include <cstring>

#include <cmath>

#include <ctype.h>

#include <map>

#include <vector>

#include <algorithm>

#include <set>

#define ll long long

using namespace std;

const int mod = 1e9 + 7;

const int N = 100000+5;

const int M = N*2;

int n,m;

typedef pair<int,int> pii;

struct Edge {

    int v, d,c;

    int next;

}edge[M];

int head[N], d[N], tot;

int cost[N];

int vis[N];

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

    edge[tot].v = v;

    edge[tot].d = d;

    edge[tot].c = c;

    edge[tot].next = head[u];

    head[u] = tot++;

}

void dij(int s) {

    priority_queue<pii, vector<pii>, greater<pii> > Q;

    for(int i = 1; i <= n; i++) d[i] = 10000000+5;

    d[s] = 0;

    cost[s] = 0;

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

    Q.push(make_pair(d[s], s));

    while(!Q.empty()) {

        pii tmp = Q.top();

        Q.pop();

        int x = tmp.second;

        if(vis[x]) continue;

        vis[x] = true;

        for(int i = head[x]; i+1; i = edge[i].next) {

            if(d[edge[i].v] > d[x] + edge[i].d) {

                d[edge[i].v] = d[x] + edge[i].d;

                cost[edge[i].v] = edge[i].c;

                Q.push(make_pair(d[edge[i].v], edge[i].v));

            }

            if(d[edge[i].v] == (d[x] + edge[i].d))

            {

                cost[edge[i].v] = min(cost[edge[i].v],edge[i].c);

            }

        }

    }

}



int main()

{

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

   {

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

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

       tot = 1;

       for(int i = 0; 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);

       }

       dij(1);

       int ans = 0;

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

       {

           ans += cost[i];

       }

       cout << ans << endl;

   }



}


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

}