// Slower C++ solution:
#pragma comment(linker, "/STACK:102400000,102400000")

//#include <bits/stdc++.h>

#include <iostream>

#include <iomanip>

#include <cstdio>

#include <cmath>

#include <cstring>

#include <climits>

#include <stdlib.h>

#include <deque>

#include <queue>

#include <stack>

#include <algorithm>

#include <list>

#include <map>

#include <set>

#include <utility>

#include <sstream>

#include <complex>

#include <string>

#include <vector>

#include <bitset>

#include <complex>

#include <functional>

#include <fstream>

#include <ctime>

#include <stdexcept>

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))

#define pb push_back

#define mp make_pair

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int,int> P;

const int INF = 0x3f3f3f3f;

const int maxn = 1e5+5;

const int mod = 1e6;

const double eps = 1e-8;

const double pi = asin(1.0)*2;

const double e = 2.718281828459;

bool Finish_read;

template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}



struct ac {

	int v;

	int dis;

	int cost;

};



int n, m;

int a, b, d, c;

int ans;

int dis[maxn];

int cost[maxn];

bool vis[maxn];

vector<ac> Adj[maxn];



void Dijkstra() {

	mem(dis, INF);

	mem(cost, INF);

	mem(vis, 0);

	dis[1] = 0;

	cost[1] = 0;

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

		int u = -1, dismin = INF, costmin = INF;

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

			if (!vis[j]) {

				if (dis[j] < dismin) {

					u = j;

					dismin = dis[j];

					costmin = cost[j];

				}

				else if (dis[j] == dismin) {

					if (cost[j] < costmin) {

						u = j;

						dismin = dis[j];

						costmin = cost[j];

					}

				}

			}

		}

		if (u == -1) {

			return;

		}

		vis[u] = 1;

		for (int j = 0; j < int(Adj[u].size()); ++j) {

			int v = Adj[u][j].v;

			if (!vis[v]) {

				if (dis[u] + Adj[u][j].dis < dis[v]) {

					dis[v] = dis[u] + Adj[u][j].dis;

					cost[v] = Adj[u][j].cost;

				}

				else if (dis[u] + Adj[u][j].dis == dis[v]) {

					if (Adj[u][j].cost < cost[v]) {

						cost[v] = Adj[u][j].cost;

					}

				}

			}

		}

	}

}



int main(int argc, char *argv[]) {

//#ifndef ONLINE_JUDGE

//	freopen("in.txt", "r", stdin);

//	freopen("out.txt", "w", stdout);

//#endif

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

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

			read(a); read(b); read(d); read(c);

			ac add;

			add.v = b;

			add.dis = d;

			add.cost = c;

			Adj[a].pb(add);

			add.v = a;

			Adj[b].pb(add);

		}

		Dijkstra();

		ans = 0;

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

			Adj[i].clear();

//			printf("dis[%d]=%d cost[%d]=%d\n", i, dis[i], i, cost[i]);

			ans += cost[i];

		}

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

	}

//#ifndef ONLINE_JUDGE

//	fclose(stdin);

//	fclose(stdout);

//	system("gedit out.txt");

//#endif

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 3.3897842337335753x):
#include <iostream>

#include <cstdio>

#include <algorithm>

#include <cmath>

#include <deque>

#include <vector>

#include <queue>

#include <string>

#include <cstring>

#include <map>

#include <stack>

#include <set>

using namespace std;

typedef long long ll;

const int inf=0x3f3f3f3f;

const int INF=2147483647;

const double pi=3.1415926535897932384626;

inline ll read(){

	ll x=0,f=1;

	char ch=getchar();

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

		if(ch=='-') f=-1;

		ch=getchar();

	}

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

		x=(x<<1)+(x<<3)+(ch^48);

		ch=getchar();

	}

	return x*f;

}

const int maxn=1e4+5;

int n,m,u,v,dd,cc,ans,d[maxn],c[maxn],vis[maxn];

struct edge{

	int to,dis,cost;

};

vector<edge> g[maxn];

void Dijkstra(){

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

	memset(d,inf,sizeof(d));

	memset(c,inf,sizeof(c));

	d[1]=0;

	c[1]=0;

	ans=0;

	while(1){

		int v=-1;

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

			if(!vis[u]&&(v==-1||d[u]<d[v])) v=u;

		}

		if(v==-1) break;

		vis[v]=1;

		ans+=c[v];

		for(int i=0;i<g[v].size();i++){

			int u=g[v][i].to,dis=g[v][i].dis,cost=g[v][i].cost;

			if(d[u]>d[v]+dis||(d[u]==d[v]+dis&&cost<c[u])){

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

				c[u]=cost;

			}

		}

	}

}

int main(){

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

		for(int i=1;i<=n;i++) g[i].clear();

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

			u=read(),v=read(),dd=read(),cc=read();

			g[u].push_back({v,dd,cc});

			g[v].push_back({u,dd,cc});

		}

		Dijkstra();

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

	}

	return 0;

}