// 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.5467892473999294x):
#include<iostream>

#include<queue>

#include<functional>

#include<cstring>



using namespace std;



#define maxn 10240 

#define INF 0x3f3f3f3f;



typedef struct edge{

	int to,dis,cos;

	edge(){}

	edge(int to,int dis,int cos):to(to),dis(dis),cos(cos){}

};

typedef pair<int ,int> P;



vector<edge>G[maxn];



int d[maxn];

int v;//定点



void dijkstra(int s){

	priority_queue<P,vector<P>,greater<P> > que;//优先输出小数据；

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

	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.dis)

			{

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

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

			}

		}

	}	

} 

int main()

{

	int m;

	while(cin>>v>>m)

	{

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

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

		{

			G[i].clear();

		}

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

		{

			int u,v,d,c;

			cin>>u>>v>>d>>c;

			u--,v--;

			G[u].push_back(edge(v,d,c));

			G[v].push_back(edge(u,d,c)); 

		}

		dijkstra(0);

		int ans=0;

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

		{

			int min=INF;

			for (int j=0;j<G[i].size();j++)

			{

				if(d[G[i][j].to]+G[i][j].dis==d[i]&&G[i][j].cos<min)

				{

					min=G[i][j].cos;

				}

				

			} 

			ans+=min;

		}cout<<ans<<endl;

	}

	return 0;

}