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

typedef pair<int, int> P;

const int inf = 1e9;
const int max_n = 10000;

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

int main()
{
  int n, m;

  while (cin >> n >> m, n){
    vector<edge> G[max_n];

    for (int i = 0; i < m; i++){
      int u, v, t, c;
      cin >> u >> v >> t >> c;
      u--; v--;
      edge e1 = {v, t, c}, e2 = {u, t, c};
      G[u].push_back(e1);
      G[v].push_back(e2);
    }

    int d[max_n];
    fill(d, d + n, inf);

    d[0] = 0;
    priority_queue<P, vector<P>, greater<P>> q;
    q.push(P(0, 0));

    while (!q.empty()){
      P p = q.top(); q.pop();
      int v = p.second;

      if (d[v] < p.first) continue;

      for (int i = 0; i < G[v].size(); i++){
        edge e = G[v][i];
        if (d[e.to] > d[v] + e.dist) {
          d[e.to] = d[v] + e.dist;
          q.push(P(d[e.to], e.to));
        }
      }
    }

    int ans = 0;

    for (int v = 1; v < n; v++){
      int mini = inf;

      for (int i = 0; i < G[v].size(); i++){
        edge e = G[v][i];

        if (d[v] == d[e.to] + e.dist && e.cost < mini){
          mini = e.cost;
        }
      }

      ans += mini;
    }

    cout << ans << endl;
  }
}