// 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.4895118263591596x):
#include "cstring"

#include "cstdio"

#include "vector"

#include "queue"

using namespace std;



const int maxn=11000;



struct edge{int to,d,c;};

edge edges[4100000];

int p;



vector<int>g[maxn];



int dis[maxn],vis[maxn],cos[maxn];

int n,m,sn;



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

{

	edges[++p].d=d;

	edges[p].to=v;

	edges[p].c=c;

	g[u].push_back(p);

}



int spfa(int s)

{

	memset(cos,0x3f3f3f3f,sizeof(cos));

	memset(dis,0x3f3f3f3f,sizeof(dis));

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

	

	queue<int>qn;

	qn.push(s);

	dis[s]=0;

	cos[s]=0;

	vis[s]=1;

	

	while(!qn.empty())

	{

		int nn=qn.front();qn.pop();

		vis[nn]=0;

		for(int i=0,d=g[nn].size();i<d;i++)

		{

			edge &e= edges[g[nn][i]];

			if(dis[e.to]>dis[nn]+e.d || ((dis[e.to]==dis[nn]+e.d) && cos[e.to]>e.c))

			{

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

				cos[e.to]=e.c;

				

				if(!vis[e.to])

				{

					qn.push(e.to);

					vis[e.to]=1;

				}

			}

		}	

	}

	return 0;

}



int main()

{

	//freopen("q.txt","r",stdin);

	int u,v,d,c;

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

	{

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

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

			g[i].clear();

		p=0;

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

		{

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

			add(u,v,d,c);

			add(v,u,d,c);

		}

		int ans=0;

		spfa(1);

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

			ans+=cos[i];

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

	}

	return 0;

}