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

#include <algorithm>

#include <cstdio>

#include <queue>

#include <cstring>

#define INF 0x3f3f3f



using namespace std;

const int MAX_V=100001;

struct node

{

    int to, dis, cost, next;

}edge[MAX_V];



int head[MAX_V], d[MAX_V], mcost[MAX_V];//mcoat一个?点??一条?

bool vis[MAX_V];

int n, m, cnt;



void add_edge(int u, int v, int d, int c)

{

    edge[cnt].to=v;

    edge[cnt].dis=d;

    edge[cnt].cost=c;

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

    head[u]=cnt++;

}



int spfa(int x)

{

    d[x]=0;         //必?！！！

    queue<int> que;

    que.push(x);

    vis[x]=true;

    while(!que.empty())

    {

        int u=que.front();

        que.pop();

        vis[u]=false;

        for(int i=head[u]; i!=-1; i=edge[i].next)

        {

            node e = edge[i];

            if(d[e.to] > d[u]+e.dis)

            {

                mcost[e.to]=e.cost;     ////??最小花?

                d[e.to] = d[u]+e.dis;

                if(!vis[e.to])

                {

                    que.push(e.to);

                    vis[e.to]=true;

                }

            }

            else if(d[u]+e.dis==d[e.to] && e.cost<mcost[e.to])   ////??最小花?

                {

                    mcost[e.to]=e.cost;

                }

        }

    }

    int ans=0;

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

    {

     //   printf("\n%d\n", mcost[i]);

        ans+=mcost[i];

    }

    return ans;

}



int main()

{

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

    {

        cnt=0;          //从0?始！！！

        memset(head, -1, sizeof(head)); //初始化在前面！！！！

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

        {

            int u, v, d, c;

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

            add_edge(u,v,d,c);

            add_edge(v,u,d,c);      //双向的路！！！

        }



        //初始化

        memset(mcost, 0, sizeof(mcost));

        fill(d, d+n+1, INF);

        fill(vis, vis+n+1, false);



        int ans=spfa(1);

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

    }



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4756705278867064x):
#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;

}