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

struct edge {
  int cur, to, dist, cost, idx;
};
typedef vector< vector< edge > > Graph;

vector< const edge* > Dijkstra(const Graph& graph) {
  typedef pair< int, int > Pi;
  typedef pair< Pi, int > Pii;
  const int INF = 1 << 30;
  vector< Pi > min_cost(graph.size(), Pi(INF, INF));
  vector< const edge* > prev(graph.size(), (edge *)NULL);
  min_cost[0] = make_pair(0, 0);
  priority_queue< Pii, vector< Pii >, greater< Pii > > que;
  que.push(make_pair(make_pair(0, 0), 0));
  while(!que.empty()) {
    Pii p = que.top(); que.pop();
    if(min_cost[p.second] < p.first) continue;
    for(int i = 0; i < graph[p.second].size(); i++) {
      const edge& e = graph[p.second][i];
      if(min_cost[e.to] <= make_pair(min_cost[p.second].first + e.dist, e.cost)) continue;
      min_cost[e.to] = make_pair(min_cost[p.second].first + e.dist, e.cost);
      prev[e.to] = &graph[p.second][i];
      que.push(make_pair(min_cost[e.to], e.to));
    }
  }
  return(prev);
}

int main()
{
  int N, M;
  while(cin >> N >> M, N) {
    Graph graph(N);    
    for(int i = 0; i < M; i++) {
      int u, v, d, c;
      cin >> u >> v >> d >> c;
      --u, --v;
      graph[u].push_back((edge){u, v, d, c, i});
      graph[v].push_back((edge){v, u, d, c, i});
    }
    vector< const edge* > prev = Dijkstra(graph); // 使った辺へのポインタ
    vector< bool > killed(M, false);
    int ret = 0;
    for(int i = 1; i < N; i++) {
      const edge* now = prev[i];
      while(now != (const edge*)NULL && !killed[now -> idx]) {
        killed[now -> idx] = true;
        ret += now -> cost;
        now = prev[now -> cur];
      }
    }
    cout << ret << endl;
  }
}