#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

template<class T> using PQ_G = priority_queue<T, vector<T>, greater<T>>;

int main() {

  for(int N, M; cin >> N >> M && (N|M);) {
    vector<vector<tuple<int, int, int>>> G(N);
    rep(_, 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);
    }

    PQ_G<tuple<int, int, int>> pq;
    pq.emplace(0, 0, 0);

    vector<int> dist(N, inf);

    ll ans = 0;
    while(!pq.empty()) {
      int d, c, p; tie(d, c, p) = pq.top(); pq.pop();
      if(dist[p] <= d) continue;
      dist[p] = d;
      ans += c;
      for(auto const& e: G[p]) {
        int _v, _d, _c; tie(_v, _d, _c) = e;
        if(dist[_v] <= d + _d) continue;
        pq.emplace(d + _d, _c, _v);
      }
    }
    cout << ans << endl;
  }

  return 0;
}