#include <bits/stdc++.h>
using namespace std;
int INF = 1000000000;
int main(){
  while (1){
    int N, M;
    cin >> N >> M;
    if (N == 0 && M == 0){
      break;
    }
    vector<vector<tuple<int, int, int>>> E(N);
    for (int i = 0; i < M; i++){
      int u, v, d, c;
      cin >> u >> v >> d >> c;
      u--;
      v--;
      E[u].push_back(make_tuple(d, c, v));
      E[v].push_back(make_tuple(d, c, u));
    }
    vector<int> d(N, INF);
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    pq.push(make_pair(0, 0));
    while (!pq.empty()){
      int c = pq.top().first;
      int v = pq.top().second;
      pq.pop();
      if (d[v] == INF){
        d[v] = c;
        for (auto edge : E[v]){
          int w = get<2>(edge);
          if (d[w] == INF){
            pq.push(make_pair(c + get<0>(edge), w));
          }
        }
      }
    }
    vector<pair<int, int>> P(N);
    for (int i = 0; i < N; i++){
      P[i] = make_pair(d[i], i);
    }
    sort(P.begin(), P.end());
    int ans = 0;
    for (int i = 1; i < N; i++){
      int cost = INF;
      for (auto edge : E[P[i].second]){
        int j = get<2>(edge);
        if (P[i].first - d[j] == get<0>(edge)){
          cost = min(cost, get<1>(edge));
        }
      }
      ans += cost;
    }
    cout << ans << endl;
  }
}
