#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
 
typedef pair<int, int> state;
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    const int INF = 1.0e9;
    for(int N, M; cin >> N >> M && N;) {
        vector<vector<tuple<int, int, int>>> G(N);
        rep(i, M) {
            int u, v, d, c;
            cin >> u >> v >> d >> c;
            --u; --v;
            G[u].emplace_back(v, d, c);
            G[v].emplace_back(u, d, c);
        }
        vector<int> mdist(N, INF), preEcos(N, INF);
        mdist[0] = preEcos[0] = 0;
        priority_queue<state, vector<state>, greater<state>> que;
        que.emplace(0, 0);
        while(!que.empty()) {
            int dis, cur;
            tie(dis, cur) = que.top(); que.pop();
            if(mdist[cur] < dis) continue;
            for(const auto& e : G[cur]) {
                int nv, ndis, ncos;
                tie(nv, ndis, ncos) = e;
                if(mdist[nv] > dis + ndis || (mdist[nv] == dis + ndis && preEcos[nv] > ncos)) {
                    mdist[nv] = dis + ndis;
                    preEcos[nv] = ncos;
                    que.emplace(mdist[nv], nv);
                }
            }
        }
        cout << accumulate(preEcos.begin(), preEcos.end(), 0) << endl;
    }
    return 0;
}