#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <map>
#include <bitset>
#include <string.h>
#include <cmath>
#include <queue>
#include <algorithm>
#define N 10005
#define P pair<int,int>
#define ll long long
#define mk(a, b) make_pair(a, b)
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
int inf = 0x3f3f3f3f;
int  n, m;
struct ac{
	int e, l, c;
	bool operator < (const ac &x) const{
		return x.l < l;
	}
};
vector<ac> g[N];
bool vis[N];
int dis[N], mon[N];
void Dijkstra() {
	mem(dis, inf);
	mem(mon, inf);
	mem(vis, false);
	dis[1] = 0;
	mon[1] = 0;
	priority_queue<ac, vector<ac> >que;
	que.push((ac){1, 0, 0});
	while (!que.empty()) {
		ac first = que.top();
		que.pop();
		int e = first.e;
		int l = first.l;
		int c = first.c;
		if (vis[e])	continue;
		// if (dis[e] < l || vis[e] || mon[e] < c)	continue;
		vis[e] = true;
		for (int j = 0; j < g[e].size(); ++j) {
			ac t = g[e][j];
			if (vis[t.e])	continue;
			if (l + t.l < dis[t.e]) {
				dis[t.e] = l + t.l;
				mon[t.e] = t.c;
				que.push((ac){t.e, dis[t.e], mon[t.e]});
			}else if (l + t.l == dis[t.e]) {
				mon[t.e] = min(mon[t.e], t.c);
			}
		}
	}

}
int main(){
// #ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
// #endif
	ios::sync_with_stdio(false);
	while (cin >> n >> m, n + m) {
		for (int i = 0; i < m; ++i) {
			int s, e, l, c;
			cin >> s >> e >> l >> c;
			g[s].push_back((ac){e, l, c});
			g[e].push_back((ac){s, l, c});
		}

		Dijkstra();
		int ans = 0;
		for (int i = 1; i <= n; ++i) {
			ans += mon[i];
			// cout << mon[i] << " ";
		}
		cout << ans << endl;
		for (int i = 1; i <= n; ++i) {
				g[i].clear();
		}
	}

	return 0;
}

