// Slower C++ solution:
#include <iostream>

#include <string>

#include <queue>

#include <cstdio>

#include <cstring>

#include <cmath>

#include <ctype.h>

#include <map>

#include <vector>

#include <algorithm>

#include <set>

#define ll long long

using namespace std;

const int mod = 1e9 + 7;

const int N = 100000+5;

const int M = N*2;

int n,m;

typedef pair<int,int> pii;

struct Edge {

    int v, d,c;

    int next;

}edge[M];

int head[N], d[N], tot;

int cost[N];

int vis[N];

void addedge(int u, int v, int d,int c) {

    edge[tot].v = v;

    edge[tot].d = d;

    edge[tot].c = c;

    edge[tot].next = head[u];

    head[u] = tot++;

}

void dij(int s) {

    priority_queue<pii, vector<pii>, greater<pii> > Q;

    for(int i = 1; i <= n; i++) d[i] = 10000000+5;

    d[s] = 0;

    cost[s] = 0;

    memset(vis, 0, sizeof(vis));

    Q.push(make_pair(d[s], s));

    while(!Q.empty()) {

        pii tmp = Q.top();

        Q.pop();

        int x = tmp.second;

        if(vis[x]) continue;

        vis[x] = true;

        for(int i = head[x]; i+1; i = edge[i].next) {

            if(d[edge[i].v] > d[x] + edge[i].d) {

                d[edge[i].v] = d[x] + edge[i].d;

                cost[edge[i].v] = edge[i].c;

                Q.push(make_pair(d[edge[i].v], edge[i].v));

            }

            if(d[edge[i].v] == (d[x] + edge[i].d))

            {

                cost[edge[i].v] = min(cost[edge[i].v],edge[i].c);

            }

        }

    }

}



int main()

{

   while(scanf("%d%d",&n,&m))

   {

       if(m == 0&& n ==0) break;

       memset(head,-1,sizeof(head));

       tot = 1;

       for(int i = 0; i < m; i++)

       {

           int u,v,d,c;

           scanf("%d%d%d%d",&u,&v,&d,&c);

           addedge(u,v,d,c);

           addedge(v,u,d,c);

       }

       dij(1);

       int ans = 0;

       for(int i = 1; i <= n; i++)

       {

           ans += cost[i];

       }

       cout << ans << endl;

   }



}


// Faster C++ solution for the same problem (measured speedup: 1.4822441212570032x):
#include <iostream>

#include <cstdio>

#include <algorithm>

#include <cmath>

#include <deque>

#include <vector>

#include <queue>

#include <string>

#include <cstring>

#include <map>

#include <stack>

#include <set>

using namespace std;

typedef long long ll;

const int inf=0x3f3f3f3f;

const int INF=2147483647;

const double pi=3.1415926535897932384626;

inline ll read(){

	ll x=0,f=1;

	char ch=getchar();

	while(ch<'0'||ch>'9'){

		if(ch=='-') f=-1;

		ch=getchar();

	}

	while(ch>='0'&&ch<='9'){

		x=(x<<1)+(x<<3)+(ch^48);

		ch=getchar();

	}

	return x*f;

}

const int maxn=1e4+5;

int n,m,u,v,dd,cc,ans,d[maxn],c[maxn],vis[maxn];

struct edge{

	int to,dis,cost;

};

vector<edge> g[maxn];

void Dijkstra(){

	memset(vis,0,sizeof(vis));

	memset(d,inf,sizeof(d));

	memset(c,inf,sizeof(c));

	d[1]=0;

	c[1]=0;

	ans=0;

	while(1){

		int v=-1;

		for(int u=1;u<=n;u++){

			if(!vis[u]&&(v==-1||d[u]<d[v])) v=u;

		}

		if(v==-1) break;

		vis[v]=1;

		ans+=c[v];

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

			int u=g[v][i].to,dis=g[v][i].dis,cost=g[v][i].cost;

			if(d[u]>d[v]+dis||(d[u]==d[v]+dis&&cost<c[u])){

				d[u]=d[v]+dis;

				c[u]=cost;

			}

		}

	}

}

int main(){

	while(~scanf("%d%d",&n,&m)&&(n+m)){

		for(int i=1;i<=n;i++) g[i].clear();

		for(int i=1;i<=m;i++){

			u=read(),v=read(),dd=read(),cc=read();

			g[u].push_back({v,dd,cc});

			g[v].push_back({u,dd,cc});

		}

		Dijkstra();

		printf("%d\n",ans);

	}

	return 0;

}