#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
typedef pair<int,int>P;
typedef pair<P,int>P1;
vector<P>v[100009];
int n,m,a1,a2,a3,a4;
int d[100009],pre[100009];
int xx[100009];
map<P,int>M;
int main(){
  while(cin>>n>>m,n){
    fill(d,d+n,(int)1e9);
    fill(xx,xx+n,(int)1e9);
    r(i,n)v[i].clear();
    r(i,m){
      cin>>a1>>a2>>a3>>a4;
      a1--,a2--;
      v[a1].push_back(P(a2,a3));
      v[a2].push_back(P(a1,a3));
      M[P(a1,a2)]=a4;
      M[P(a2,a1)]=a4;
    }
    priority_queue<P1,vector<P1>,greater<P1> >q;
    d[0]=0;
    int ans=0;
    q.push(P1(P(0,0),0));
    while(!q.empty()){
      P1 p=q.top();q.pop();
      int cost=p.first.first;
      int now=p.second;
      if(d[now]<cost)continue;
      d[now]=cost;
      xx[now]=min(xx[now],p.first.second);
      r(i,v[now].size()){
        P p=v[now][i];
        int next=p.first;
        int cost2=cost+p.second;
        if(d[next]>=cost2){
          q.push(P1(P(cost2,M[P(now,next)]),next));
        }
      }
    }
    r(i,n-1)ans+=xx[i+1];
    cout<<ans<<endl;
  }
}