#include <bits/stdc++.h>
using namespace std;

typedef tuple<int, int, int> Edge;
const int INF = 1 << 28;

int n, m;
vector<vector<Edge>> g;

int main()
{
	while (cin >> n >> m, n){
		g.clear(); g.resize(n);
		for (int i = 0; i < m; i++){
			int a, b, d, c;
			cin >> a >> b >> d >> c, a--, b--;
			g[a].emplace_back(d, c, b);
			g[b].emplace_back(d, c, a);
		}
		int res = 0;
		vector<pair<int, int>> dist(n, make_pair(INF, INF));
		priority_queue<Edge, vector<Edge>, greater<Edge>> pq;
		dist[0] = make_pair(0, 0);
		pq.push(Edge(0, 0, 0));
		while (pq.size()){
			int s, c, v;
			tie(s, c, v) = pq.top(); pq.pop();
			if (dist[v] < make_pair(s, c)) continue;
			res += c;
			for (Edge &e : g[v]){
				int d, co, u;
				tie(d, co, u) = e;
				if (dist[u] > make_pair(s + d, co)){
					dist[u] = make_pair(s + d, co);
					pq.push(Edge(s + d, co, u));
				}
			}
		}
		cout << res << endl;
	}
}