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

#include <algorithm>

#include <cstdio>

#include <queue>

#include <cstring>

#define INF 0x3f3f3f



using namespace std;

const int MAX_V=100001;

struct node

{

    int to, dis, cost, next;

}edge[MAX_V];



int head[MAX_V], d[MAX_V], mcost[MAX_V];//mcoat一个?点??一条?

bool vis[MAX_V];

int n, m, cnt;



void add_edge(int u, int v, int d, int c)

{

    edge[cnt].to=v;

    edge[cnt].dis=d;

    edge[cnt].cost=c;

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

    head[u]=cnt++;

}



int spfa(int x)

{

    d[x]=0;         //必?！！！

    queue<int> que;

    que.push(x);

    vis[x]=true;

    while(!que.empty())

    {

        int u=que.front();

        que.pop();

        vis[u]=false;

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

        {

            node e = edge[i];

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

            {

                mcost[e.to]=e.cost;     ////??最小花?

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

                if(!vis[e.to])

                {

                    que.push(e.to);

                    vis[e.to]=true;

                }

            }

            else if(d[u]+e.dis==d[e.to] && e.cost<mcost[e.to])   ////??最小花?

                {

                    mcost[e.to]=e.cost;

                }

        }

    }

    int ans=0;

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

    {

     //   printf("\n%d\n", mcost[i]);

        ans+=mcost[i];

    }

    return ans;

}



int main()

{

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

    {

        cnt=0;          //从0?始！！！

        memset(head, -1, sizeof(head)); //初始化在前面！！！！

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

        {

            int u, v, d, c;

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

            add_edge(u,v,d,c);

            add_edge(v,u,d,c);      //双向的路！！！

        }



        //初始化

        memset(mcost, 0, sizeof(mcost));

        fill(d, d+n+1, INF);

        fill(vis, vis+n+1, false);



        int ans=spfa(1);

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

    }



    return 0;

}

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



struct node{

	int to,next,dis,cost;

}edge[40100];

int head[10100];

int dis[10100],cost[10100];

bool vst[10100];

int n,m,k;



void spfa(int x)

{

	clean(dis,INF);

	clean(cost,INF);

	clean(vst,0);

	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;

			}

		}

	}

}



void add(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++;

}



int main()

{

	while(cin>>n>>m&&n!=0||m!=0)

	{

		clean(head,-1);

		k=0;

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

		{

			int a,b,d,c;

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

			add(a,b,d,c);

			add(b,a,d,c);

		}

		spfa(1);

		ll res=0;

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

			res=res+cost[i];

		cout<<res<<endl;

	}

}