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

struct edge {
    int to, dist, cost;
};

using edges = vector<edge>;
using graph = vector<edges>;

constexpr int INF = 1e9;

int main() {
    int N, M;
    while(cin >> N >> M, N) {
        vector<int> d(N, INF);
        vector<int> cost(N, INF);
        graph g(N);
        for(int i=0; i<M; ++i) {
            int a, b, d, c;
            cin >> a >> b >> d >> c;
            a--; b--;
            g[a].push_back((edge){b, d, c});
            g[b].push_back((edge){a, d, c});
        }
        using state = tuple<int, int, int>;
        priority_queue<state, vector<state>, greater<state>> que;
        que.push(make_tuple(0, 0, 0));
        d[0] = 0;
        cost[0] = 0;
        while(!que.empty()) {
            int dis, cos, v;
            tie(dis, cos, v) = que.top();
            que.pop();
            if(d[v] < dis || cost[v] < cos) {
                continue;
            }
            for(auto& e : g[v]) {
                if(d[e.to] > d[v] + e.dist || d[e.to] == d[v] + e.dist && cost[e.to] > e.cost) {
                    d[e.to] = d[v] + e.dist;
                    cost[e.to] = e.cost;
                    que.push(make_tuple(d[e.to], cost[e.to], e.to));
                }
            }
        }
        cout << accumulate(cost.begin()+1, cost.end(), 0) << endl;
    }
}
