// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
class DIJ{
	public:
	struct edge{
		int to,cost,val;
	};
	vector<vector<edge> >G;
	int n;
	vi d;//distance
	DIJ(int size){
		n=size;
		G=vector<vector<edge> >(n);
	}
	void add_edge(int a,int b,int c,int d){
		edge e={b,c,d},ee={a,c,d};
		G[a].pb(e);
		G[b].pb(ee);
	}
	void dij(int s){
		d=vi(n,inf);
		d[s]=0;
		priority_queue<pii>q;
		q.push(pii(0,s));
		while(!q.empty()){
			pii p=q.top();
			q.pop();
			int pos=p.second,cost=-p.first;
			if(cost>d[pos])continue;
			rep(i,G[pos].size()){
				edge e=G[pos][i];
				int to=e.to;
				int nowcost=cost+e.cost;
				if(nowcost<d[to]){
					d[to]=nowcost;
					q.push(pii(-d[to],to));
				}
			}
		}
	}
};
class SCC{//cmp(0 - kk-1) is scc's return. Same number is group. The number is no relatoin.
	public:
	int n,N;
	vvi G,rG;
	vector<bool>used;
	vi vs,cmp;
	SCC(int size){
		n=size;
		G=rG=vvi(n);
		used=vector<bool>(n);
		cmp=vi(n);
		vs=vi(0);
	}
	void add_edge(int s,int t){
		G[s].pb(t);
		rG[t].pb(s);
	}
	void rdfs(int v,int k){
		used[v]=true;
		cmp[v]=k;
		rep(i,rG[v].size())if(!used[rG[v][i]])rdfs(rG[v][i],k);
	}
	void dfs(int v){
		used[v]=true;
		rep(i,G[v].size())if(!used[G[v][i]])dfs(G[v][i]);
		vs.pb(v);
	}
	int scc(){
		rep(i,n)used[i]=false;
		rep(v,n)if(!used[v])dfs(v);
		rep(i,n)used[i]=false;
		N=0;
		for(int i=vs.size()-1;i>=0;i--)if(!used[vs[i]])rdfs(vs[i],N++);
		return N;
	}
	vvi make(){
		vvi tG(N);
		rep(i,n)rep(j,G[i].size())if(cmp[i]!=cmp[G[i][j]]){
			tG[cmp[i]].pb(cmp[G[i][j]]);
//			tG[cmp[G[i][j]]].pb(cmp[i]);
		}
		return tG;
	}
};
struct edge{
	int to,cost;
};
class MCA{
	public:
	int n,r;
	vector<vector<edge> >G,rG,tG,trG;
	vector<bool>used;
	MCA(int size,int R){
		r=R;
		n=size;
		rG=G=vector<vector<edge> >(n);
	}
	void add_edge(int s,int t,int cost){
		edge e={t,cost},ee={s,cost};
		G[s].pb(e);rG[t].pb(ee);
	}
	void dfs(int s){
		used[s]=true;
		rep(i,tG[s].size())if(!used[tG[s][i].to])dfs(tG[s][i].to);
	}
	int mca(){
		tG=trG=vector<vector<edge> >(n);
		rep(i,n)if(i!=r){
			int mi=inf;
			rep(j,rG[i].size())mi=min(mi,rG[i][j].cost);
			rep(j,rG[i].size())if(mi==rG[i][j].cost){
				edge e={i,rG[i][j].cost};
				tG[rG[i][j].to].pb(e);
				trG[i].pb(rG[i][j]);
				break;
			}
		}
		used=vector<bool>(n);
		dfs(r);
		bool h=true;
		rep(i,n)if(!used[i])h=false;
		if(h){//connect
			int sum=0;
			rep(i,n)rep(j,tG[i].size())sum+=tG[i][j].cost;
			return sum;		
		}else{// not connect
			SCC scc(n);
			rep(i,n)rep(j,tG[i].size())scc.add_edge(i,tG[i][j].to);
			int N=scc.scc();
			MCA mca(N,scc.cmp[r]);
			int sum=0;
			rep(i,n)rep(j,tG[i].size())if(scc.cmp[i]==scc.cmp[tG[i][j].to])sum+=tG[i][j].cost;
			rep(i,n)rep(j,G[i].size())if(scc.cmp[i]!=scc.cmp[G[i][j].to]){
				bool h=false;
				int To=G[i][j].to;//i -> To
				rep(k,n)if(To!=k&&scc.cmp[To]==scc.cmp[k])h=true;
				if(h){
					mca.add_edge(scc.cmp[i],scc.cmp[To],G[i][j].cost-trG[To][0].cost);
				}else{
					mca.add_edge(scc.cmp[i],scc.cmp[To],G[i][j].cost);
				}
			}
			return sum+mca.mca();
		}
		return false;
	}
};
int main(){
	int n,m;
	while(cin>>n>>m,n){
		DIJ dij(n);
		rep(i,m){
			int a,b,c,d;
			cin>>a>>b>>c>>d;
			a--;b--;
			dij.add_edge(a,b,c,d);
		}
		dij.dij(0);
		vi d=dij.d;
		MCA mca(n,0);
		rep(i,n)rep(j,dij.G[i].size())if(d[i]+dij.G[i][j].cost==d[dij.G[i][j].to])
			mca.add_edge(i,dij.G[i][j].to,dij.G[i][j].val);
		cout<<mca.mca()<<endl;
	}
}








Measured memory_bytes: 5232