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

#include <cstdio>

#include <queue>

#include <string.h>



using namespace std;



#define MAXN 10001

#define INF 999999999





struct Edge

{

	int u, v, next, d, c;

}edge[MAXN * 4];



int head[MAXN], e;

int n, m;

int total;

int dis[MAXN];

int cost[MAXN];

bool vis[MAXN];



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

{

	edge[e].u = u;

	edge[e].v = v;

	edge[e].d = d;

	edge[e].c = c;

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

	head[u] = e++;

}



void init()

{

	e = 0;

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

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

}



queue <int> q;



void solve()

{

	while (!q.empty())

	{

		q.pop();

	}

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

	{

		dis[i] = INF;

		cost[i] = INF;

	}

	

	int cur, next, ans = 0;

	q.push(1);

	vis[1] = true;

	dis[1] = 0;

	cost[1] = 0;

	

	while (!q.empty())

	{

		cur = q.front();

		q.pop();

		vis[cur] = false;

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

		{

			int v = edge[i].v;

				if (dis[v] > dis[cur] + edge[i].d)

				{

					dis[v] = dis[cur] + edge[i].d;

					cost[v] = edge[i].c;

					if(!vis[v])

				     {

					vis[v] = true;

					q.push(v);

				    }

				}

				else if (dis[v] == dis[cur] + edge[i].d && cost[v] > edge[i].c)

	             {

			

					cost[v] = edge[i].c;

					if(!vis[v])

			     	{

					vis[v] = true;

					q.push(v);

				    }

				}

				

		}

		

		

	}

	

	int ss = 0;

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

	{

		ss += cost[i];

	}

	

	cout << ss << endl;

}



void input()

{

	int u, v, d, c;

	

	while (cin >> n >> m)

	{

		total = 0;

		if (!n && !m)

		{

			break;

		}

		init();

		

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

		{

			cin >> u >> v >> d >> c;

			add(u, v, d, c);

			add(v, u, d, c);

			total += 2 * c;

		}

		

		solve();

	}

}



int main()

{

	std::ios::sync_with_stdio(false);

	input();

	return 0;

}

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

}