// 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.2437619775766933x):
#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;

}