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

#include<cstdio>

#include<vector>

#include<cstring>

#include<iostream>

#include<algorithm>

#define RG register

#define LL long long

#define fre(a) freopen(a".in","r",stdin);//freopen(a".out","w",stdout);

using namespace std;

const int MAXN=50000;

int n,m,num;

int head[MAXN],to[MAXN],len[MAXN],cost[MAXN],Next[MAXN];

int dis[MAXN],pre[MAXN],pree[MAXN];

bool vis[MAXN],use[MAXN];

queue<int>que;

void add(int f,int t,int l,int c)

{

   Next[++num]=head[f];

   to[num]=t;

   len[num]=l;

   cost[num]=c;

   head[f]=num;

}

void SPFA()

{

   que.push(1);

   dis[1]=0;

   while(!que.empty())

      {

	 int now=que.front();

	 que.pop(); vis[now]=0;

	 for(int i=head[now];i;i=Next[i])

	    {

	       int son=to[i];

	       if(dis[now]+len[i]<dis[son])

		  {

		     dis[son]=dis[now]+len[i];

		     pre[son]=now;

		     pree[son]=i;

		     if(!vis[son])

			{

			   vis[son]=1;

			   que.push(son);

			}

		  }

	       else if(dis[now]+len[i]==dis[son])

		  {

		     if(cost[i]<cost[pree[son]])

			pree[son]=i,pre[son]=now;

		  }

	    }

      }

}

int main()

{

   //fre("1");

   while(1)

      {

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

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

	 num=0;

	 memset(head,0,sizeof head);

	 for(int i=1,a,b,c,d;i<=m;i++)

	    {

	       scanf("%d%d%d%d",&a,&b,&c,&d);

	       add(a,b,c,d); add(b,a,c,d);

	    }

	 memset(dis,0x3f3f3f3f,sizeof dis);

	 memset(vis,0,sizeof vis);

	 memset(use,0,sizeof use);

	 //memset(pree,0,sizeof pree);

	 SPFA();

	 //for(int i=1;i<=n;i++)printf("dis[%d]=%d\n",i,dis[i]);printf("----------------\n");

	 int ans=0;

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

	    for(int j=i;j>1;j=pre[j])

	       if(!use[pree[j]])

		  ans+=cost[pree[j]],use[pree[j]]=1;

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

      }

   return 0;

}

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

using namespace std;

const int maxn = 2e4+9;

const int inf = 0x3f3f3f3f;

typedef long long int ll;

typedef pair<int,int> pi;

struct {

    int v,nex,d,c;

}e[maxn*2];

int in[maxn];

int dis[maxn];

int head[maxn];

int tot;

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

    e[tot] ={v,head[u],d,c};

    head[u] = tot++;

}

int dd[maxn];

priority_queue<pi> qq;

int main()

{

    int n,m;

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

            tot =0;

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

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

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

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

        memset(in,0,sizeof(in));



        while(!qq.empty()){

            qq.pop();

        }

        qq.push(pi(0,1));

        dis[1] =0;

        dd[1] = 0;



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

        }

        while(!qq.empty()){

            pi now = qq.top();

            qq.pop();

            int pp = now.second;

            if(in[pp]==1) continue;

            in[pp] = 1;

            for(int i=head[pp];i!=-1;i=e[i].nex){

                int v= e[i].v;

                int d = e[i].d;

                if(in[v]==1) continue;

                if( dis[pp]+d<dis[v]){

                    dis[v] = dis[pp]+d;

                    dd[v] = e[i].c;

                    qq.push(pi(-dis[v],v));

                }else if(dis[pp]+d==dis[v]){

                    dd[v] = min(dd[v],e[i].c);

                }

            }

        }

        int ans = 0;

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

            ans+=dd[i];

        }

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

    }

    return 0;

}