// Slower C++ solution:
#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;

}




// Faster C++ solution for the same problem (measured speedup: 1.1142591033744467x):
    #include <stdio.h>

    #include <string.h>

    #include <queue>

    #include <iostream>

    #include <algorithm>

    using namespace std;

    const int maxn=10050;

    const int maxe=2005000;

    const int INF=1e9;

    struct note

    {

        int to;

        int w;

        int c;

        int next;

    };

    note edge[maxe];

    int head[maxn];

    int ip;

    void init()

    {

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

        ip=0;

    }

    void addedge(int u,int v,int w,int c)

    {

        edge[ip].to=v;

        edge[ip].c=c;

        edge[ip].w=w;

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

        head[u]=ip++;

    }

    int cost[maxn];

    int dis[maxn];

    bool vis[maxn];

    queue<int>q;

    void spfa(int s,int n)

    {

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

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

            cost[i]=dis[i]=INF;

        memset(vis,false,sizeof(vis));

        dis[s]=0;

        cost[s]=0;

        vis[s]=true;

        q.push(s);

        while(!q.empty())

        {

            int u=q.front();

            q.pop();

            vis[u]=false;

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

            {

                int to=edge[i].to;

                int val=edge[i].w;

                if(dis[to]>dis[u]+val||(dis[to]==dis[u]+val&&cost[to]>edge[i].c))//有多条最短路时，取花费最小的

                {

                    dis[to]=dis[u]+val;

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

                    if(!vis[to])

                    {

                        q.push(to);

                        vis[to]=true;

                    }

                }

            }

        }

    }

    int main()

    {

        int n,m;

        int u,v,w,c;

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

        {

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

            init();

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

            {

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

                addedge(u,v,c,w);

                addedge(v,u,c,w);

            }

            spfa(1,n);

            int ans=0;

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

                ans+=cost[i];

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

        }

        return 0;

    }