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

#include<vector>

#include<queue>

#include<algorithm>

#include<cstring>

using namespace std;

const int maxn  = 1e4+10;

const int INF = 0x3f3f3f3f;

typedef pair<int,int> P;

struct edge{

	int to,dis,cost;

		

};



int d[maxn];

int value[maxn];



int N,M;



int dijkstra(vector<edge>G[])

{



	memset(d,INF,sizeof(d));

	//memset(value,INF,sizeof(value));

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

		

	d[1] = 0;

	value[1] = 0;

	que.push(P(d[1],1));

	

	int res = 0;

	while(!que.empty())

	{

		P p  = que.top(); que.pop();

		

		int v = p.second;

		if(d[v] < p.first)

			continue;

			

		res += value[v];

		

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

		{

			edge e = G[v][i];

			if(d[e.to] == d[v] + e.dis)

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

			if(d[e.to] > d[v] + e.dis)

			{

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

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

				

				value[e.to] = e.cost;

			}

		}

	}

	return res;

	

}



int main()

{



	//freopen("c:\\users\\administrator\\desktop\\in.txt","r",stdin);

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

	{

		

		vector<edge> G[maxn];

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

		{

			int u,v,d,c;

			edge e;

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

			e.to= v, e.dis= d, e.cost =c;

			G[u].push_back(e);

			e.to= u;

			G[v].push_back(e);	

		}

		

		int res = dijkstra(G);

		cout << res <<endl;

	}		

} 

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

    #include <string.h>

    #include <queue>

    #include <iostream>

    #include <algorithm>

    using namespace std;

    const int maxn=10050;

    const int maxe=2005000;

    const int INF=1e9;

    struct note

    {

        int to;

        int w;

        int c;

        int next;

    };

    note edge[maxe];

    int head[maxn];

    int ip;

    void init()

    {

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

        ip=0;

    }

    void addedge(int u,int v,int w,int c)

    {

        edge[ip].to=v;

        edge[ip].c=c;

        edge[ip].w=w;

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

        head[u]=ip++;

    }

    int cost[maxn];

    int dis[maxn];

    bool vis[maxn];

    queue<int>q;

    void spfa(int s,int n)

    {

        while(!q.empty())q.pop();

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

            cost[i]=dis[i]=INF;

        memset(vis,false,sizeof(vis));

        dis[s]=0;

        cost[s]=0;

        vis[s]=true;

        q.push(s);

        while(!q.empty())

        {

            int u=q.front();

            q.pop();

            vis[u]=false;

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

            {

                int to=edge[i].to;

                int val=edge[i].w;

                if(dis[to]>dis[u]+val||(dis[to]==dis[u]+val&&cost[to]>edge[i].c))//有多条最短路时，取花费最小的

                {

                    dis[to]=dis[u]+val;

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

                    if(!vis[to])

                    {

                        q.push(to);

                        vis[to]=true;

                    }

                }

            }

        }

    }

    int main()

    {

        int n,m;

        int u,v,w,c;

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

        {

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

            init();

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

            {

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

                addedge(u,v,c,w);

                addedge(v,u,c,w);

            }

            spfa(1,n);

            int ans=0;

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

                ans+=cost[i];

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

        }

        return 0;

    }