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

#include <stdio.h>

#include <string.h>

#include <queue>

using namespace std;

const int maxn=10050,maxm=20050,inf=0x3f3f3f3f;

struct Edge

{

    int to,next,dis,cos ;

}edge[maxm*2];

struct Pair

{

    int D,V,C;

    Pair(){;}

    Pair(int d,int c,int v)

    {

        D=d,V=v,C=c;

    }

    friend bool operator <(const Pair a,const Pair b)

    {

        if(a.D!=b.D)

        return a.D>b.D;

        else return a.C>b.C;

    }

};

int tot,head[maxn],dist[maxn],cost[maxn];

bool vis[maxn];

void init()

{

    tot=0;

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

}

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

{

    edge[tot].to=v;

    edge[tot].dis=d;

    edge[tot].cos=c;

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

    head[u]=tot++;

}

int dijstra(int start)

{

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

    memset(dist,inf,sizeof(dist));

    int ans=0;

    dist[start]=0;

   // vis[start]=true;

    priority_queue<Pair>que;

    que.push(Pair(0,0,start));

    while(!que.empty())

    {

        Pair now=que.top();

        que.pop();

        if(vis[now.V])

            continue;

        vis[now.V]=true;

        ans+=now.C;

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

        {

            int to=edge[i].to;

            que.push(Pair(now.D+edge[i].dis,edge[i].cos,to));

        }

    }

    return ans;

}

int main()

{

    int u,v,d,c;

    int n,m;

    while(scanf("%d%d",&n,&m)!=-1)

    {

        init();

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

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

        {

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

            add_edge(u,v,d,c);

            add_edge(v,u,d,c);

        }

        printf("%d\n",dijstra(1));

    }

    return 0;

}

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

using namespace std;



#define db double

#define ll long long

#define RG register



inline int gi()

{

	RG int ret; RG bool flag; RG char ch;

	ret=0, flag=true, ch=getchar();

	while (ch < '0' || ch > '9')

		ch == '-' ? flag=false : 0, ch=getchar();

	while (ch >= '0' && ch <= '9')

		ret=(ret<<3)+(ret<<1)+ch-'0', ch=getchar();

	return flag ? ret : -ret;

}



const db pi = acos(-1.0);

const int N = 142857, inf = 1<<30;



int f[N],et[N],ed[N],nx[N],ew[N],dis[N],cst[N];

bool vis[N];

queue <int> q;

int num;



inline void add(int x,int y,int z,int w)

{

	et[++num]=y, nx[num]=f[x], ed[num]=z, ew[num]=w, f[x]=num;

}



int main()

{

	int n,m,i,x,y,z,w;

	while (true)

		{

			n=gi(), m=gi();

			if (n == 0)

				break;

			for (i=1; i<=m; ++i)

				{

					x=gi(), y=gi(), z=gi(), w=gi();

					add(x,y,z,w), add(y,x,z,w);

				}

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

				cst[i]=dis[i]=inf;

			q.push(1), vis[1]=true;

			while (!q.empty())

				{

					x=q.front(), q.pop(), vis[x]=false;

					for (i=f[x]; i; i=nx[i])

						{

							y=et[i], z=ed[i], w=ew[i];

							if (dis[y] > dis[x]+z)

								{

									dis[y]=dis[x]+z;

									cst[y]=cst[x]+w;

									if (!vis[y])

										q.push(y), vis[y]=true;

								}

							if (dis[y] == dis[x]+z && cst[y] > w)

								cst[y]=w;

						}

				}

			x=0;

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

				x+=cst[i];

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

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

				f[i]=0;

			num=0;

		}

	return 0;

}