#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>

using namespace std;

typedef pair<int, int> P;

class Edge{
public:
  int to, dist, cost;
  Edge(){}
  Edge(int to, int dist, int cost) : to(to), dist(dist), cost(cost) {}
};

static const int N = 10000;
static const int INF = (1<<28);

vector<Edge> G[N];
vector<int> prevc[N];
int dist[N], n, m;

int solve(){
  fill(dist, dist+n, INF);
  priority_queue<P, vector<P>, greater<P> > q;
  dist[0] = 0;
  q.push(P(0, 0));
  while(!q.empty()){
    P u = q.top(); q.pop();
    if(dist[u.second] < u.first) continue;
    for(int i=0;i<G[u.second].size();i++){
      Edge& e = G[u.second][i];
      if(dist[e.to] > dist[u.second] + e.dist){
        dist[e.to] = dist[u.second] + e.dist;
        prevc[e.to].clear();
        prevc[e.to].push_back(e.cost);
        q.push(P(dist[e.to], e.to));
      }else if(dist[e.to] == dist[u.second] + e.dist) prevc[e.to].push_back(e.cost);
    }
  }
  int res = 0;
  for(int i=1;i<n;i++){
    int tmp = INF;
    for(int j=0;j<prevc[i].size();j++) tmp = min(tmp, prevc[i][j]);
    res += tmp;
  }
  return res;
}

int main(){
  while(cin >> n >> m && (n|m)){
    for(int i=0;i<n;i++){
      G[i].clear();
      prevc[i].clear();
    }
    for(int i=0;i<m;i++){
      int u, v, d, c;
      cin >> u >> v >> d >> c;
      G[u-1].push_back(Edge(v-1, d, c));
      G[v-1].push_back(Edge(u-1, d, c));
    }
    cout << solve() << endl;
  }
}