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

#include<queue>

#include<cstdlib>

#include<cstdio>

#include<cstring>



using namespace std;

const int maxn=4e4+100;

const int inf=0x3f3f3f3f;



struct Edge{

    int next;

    int to;

    int w;

    int  c;



}G[maxn];



int inq[maxn];

int dis[maxn];

int head[maxn];

int k=0;





void adde(int v,int to,int w,int c)//加?

{

    G[k].to=to;//第k条?指向的点

    G[k].w=w;//第k条?的??

    G[k].c=c;

    G[k].next=head[v];//与第k条??同起点的上一条?的?存位置

    head[v]=k++;

}



queue<int>Q;



void spfa(int s)

{

        while(!Q.empty())Q.pop();

        memset(inq,0,sizeof(inq));

        memset(dis,inf,sizeof(dis));

        dis[s] = 0;

        inq[s] = 1;

        Q.push(s);

        while(!Q.empty())

        {

                int u = Q.front();

                Q.pop();

                inq[u]=0;

                for(int i=head[u];i!=-1;i=G[i].next)//遍?以u?起点的所有?

                {

                        int v=G[i].to;

                        if(dis[v]>dis[u]+G[i].w)

                        {

                                dis[v]=dis[u]+G[i].w;

                                if(inq[v]==0)

                                {

                                    Q.push(v);

                                    inq[v]=1;

                                }

                        }

                }

                inq[u]=0;



        }

}



int main()

{

        int n,m;

        while(scanf("%d%d",&n,&m)!=EOF)

        {

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

                        return 0;

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



                k=0;

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

                {

                            int a,b,c,d;

                            scanf("%d%d%d%d",&a,&b,&c,&d);

                            adde(a,b,c,d);

                            adde(b,a,c,d);

                }

                spfa(1);

                int ans=0;

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

                {

                        int mi=inf;

                        for(int j=head[i];j!=-1;j=G[j].next)

                        {

                                if(dis[G[j].to]+G[j].w==dis[i]&&G[j].c<mi)

                                        mi=G[j].c;

                        }

                        ans+=mi;

                }

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

        }

        return 0;



}

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

#include <queue>

#include <vector>

#include <algorithm>



using namespace std;

const int INF = 0x3f3f3f3f;



const int maxn = 10240;



struct edge {

	int to, dis, cost;

	edge(int t, int d, int c) : to(t), dis(d), cost(c) {}

};





typedef pair<int, int> p;

priority_queue<p, vector<p>, greater<p> > q;

vector<edge> g[maxn];



int N, M;



void read_in() {

	//scanf("%d%d", &N, &M);

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

		g[i].clear();



	int from, to, dis, cost;

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

		scanf("%d%d%d%d", &from, &to, &dis, &cost);

		g[from].push_back(edge(to, dis, cost));

		g[to].push_back(edge(from, dis, cost));

	}

}



int solve() {

	q.push(p(0, 1));



	const int INF = 0x7777777;

	int d[maxn];



	for(int i = 2; i <= N; i++) 

		d[i] = INF;

	d[1] = 0;



	while( !q.empty() ) {

		p t = q.top();

		q.pop();



		int to = t.second, dis = t.first;

        if(d[to] < dis) continue;

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

			edge To = g[to][i];

			if(d[To.to] > d[to] + To.dis)

				d[To.to] = d[to] + To.dis,

				q.push(p(d[To.to], To.to));

		}

	}

	//show(d);

    int ans = 0;



    for(int i = 2; i <= N; i++) {

        int tmp = INF;



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

            edge e = g[i][j];

            if(d[e.to] + e.dis == d[i] and e.cost < tmp)

                tmp = e.cost;

        }

        ans += tmp;

    }



    return ans;

}



int main() {

	while(scanf("%d %d", &N, &M) and N) {

		read_in();

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

	}

	return 0;

}