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

#include<cstring>

#include<queue>

#include<vector>

using namespace std;

#define INF 1000000000

#define pb push_back

#define maxn 10001

struct Edge{

	int from, to, dist, cost;

};

struct HeapNode{

	int d, u, c;

	bool operator < (const HeapNode& a)const{

		if(d==a.d)	return c>a.c;

		return d>a.d;

	}

};

inline void IN(int& x){

	x=0;

	char c=getchar();

	while(c<48 || c>57)	c=getchar();

	while(c>=48 && c<=57){

		x=x*10+c-48;

		c=getchar();

	}

}

int n, m;

vector<Edge> edges;

vector<int> G[maxn];

vector<int> V[maxn];

bool done[maxn];

int d[maxn], p[maxn], c[maxn];

int ans;

void init(){

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

		G[i].clear();

		V[i].clear();

	}

	edges.clear();

}

void add(int from, int to, int dist, int cost){

	edges.pb((Edge){from, to, dist, cost});

	m = edges.size();

	G[from].pb(m-1);

	V[from].pb(cost);

}

void dijkstra(int s){

	ans=0;

	priority_queue<HeapNode> Q;

	for(int i=1; i<=n; i++)	d[i]=INF;

	for(int i=1; i<=n; i++)	c[i]=INF;

	d[s]=0;

	c[s]=0;

	memset(done, 0, sizeof(done));

	Q.push((HeapNode){0,s,0});

	while(!Q.empty()){

		HeapNode x = Q.top(); Q.pop();

		int u=x.u;

		if(done[u])	continue;

		done[u]=1;

		ans += c[u];

		for(int i=0; i<G[u].size(); i++){

			Edge& e = edges[G[u][i]];

			if(d[e.to]>d[u]+e.dist || (d[e.to]==d[u]+e.dist && c[e.to]>V[u][i])){

				d[e.to] = d[u]+e.dist;

				p[e.to] = G[u][i];

				c[e.to] = V[u][i];

				Q.push((HeapNode){d[e.to],e.to,c[e.to]});

			}

		}

	}

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

}

int k;

int main(){

	while(1){

		IN(n); IN(k);

		if(!n && (!k))	break;

		int a, b, c, d;

		init();

		while(k--){

			IN(a); IN(b); IN(c); IN(d);

			add(a, b, c, d);

			add(b, a, c, d);

		}

		dijkstra(1);

	}

	return 0;

}

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

#include <cstring>

#include <algorithm>



using namespace std;



constexpr int maxN = 10005;

constexpr int maxM = 400005;



int N, M;



int adj[maxN], gto[maxM], gnxt[maxM], length[maxM], cost[maxM], e;

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

    gto[e] = v; length[e] = d; cost[e] = c; gnxt[e] = adj[u]; adj[u] = e++;

}



void print_edge(int s) {

    printf("%d:", s);

    for (int e = adj[s]; ~e; e = gnxt[e])

        printf(" %d", gto[e]);

    putchar('\n');

}



int dis[maxN], pre[maxN];

int qu[maxN], qh, qt; bool inq[maxN];

void bellman_ford(int s) {

    memset(dis, 0x3f, sizeof dis); dis[s] = 0;

    for (inq[qu[qh = qt = 0] = s] = 1; qh <= qt; inq[qu[qh++ % N]] = 0)

        for (int u = qu[qh % N], e = adj[u], v = gto[e]; ~e; v = gto[e = gnxt[e]])

            if (dis[v] > dis[u] + length[e]) {

                dis[v] = dis[u] + length[e];

                pre[v] = cost[e];

                if (!inq[v]) inq[qu[++qt % N] = v] = 1;

            } else if (dis[v] == dis[u] + length[e]) {

                pre[v] = min(pre[v], cost[e]);

            }

}



int main() {

    while (~scanf("%d%d", &N, &M) && (N || M)) {

        memset(adj, -1, sizeof adj);

        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);

        }

        bellman_ford(1);

        long long ans = 0;

        for (int i = 1; i <= N; ++i) ans += pre[i];

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

    }

    return 0;

}