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

#include <cstring>

#include <queue>

#define inf 0x3f3f3f3f

#define maxm 10005

#define maxn 40005



using namespace std;



int m,n;

long long edgenum,head[maxm],dis[maxm],num[maxm],ans;

bool vis[maxm];



struct node

{

    int from,to,len,cost,next;

}edge[maxn];



void init()

{

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

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

    memset(dis,inf,sizeof(dis));

    memset(num,inf,sizeof(num));

    edgenum=0;

}



void add(int u,int v,int len,int cost)

{

    node tp={u,v,len,cost,head[u]};

    edge[edgenum]=tp;

    head[u]=edgenum++;

}



long long SPFA(int st)

{

     queue<int> q;

     q.push(st);

     vis[st]=1;

     dis[st]=0;

     num[st]=0;

     ans=0;

     while(!q.empty())

     {

          int tmp=q.front();

          q.pop();

          vis[tmp]=0;

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

          {

                if((dis[edge[i].to]>dis[tmp]+edge[i].len)||((dis[edge[i].to]==dis[tmp]+edge[i].len)&&(num[edge[i].to]>edge[i].cost)))

                {

                    dis[edge[i].to]=dis[tmp]+edge[i].len;

                    num[edge[i].to]=edge[i].cost;

                    if(!vis[edge[i].to])

                    {

                        q.push(edge[i].to);

                        vis[edge[i].to]=1;

                    }

                }

          }

     }

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

        ans+=num[i];

     return ans;

}



int main()

{

    int u,v,len,cost;

    while(cin>>m>>n&&m)

    {

        init();

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

        {

            cin>>u>>v>>len>>cost;

            add(u,v,len,cost);

            add(v,u,len,cost);

        }

        cout<<SPFA(1)<<endl;

    }

    return 0;

}

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

}