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

#include <queue>

#include <functional>

#include <cstring>

using namespace std;

#define MAX_V 10240

 

// 从?点from指向?点to的???cost的?

typedef struct edge

{

	int to, distance, cost;

	edge(){}

	edge(int to, int distance, int cost) : to(to), distance(distance), cost(cost){}

	bool operator > (const edge & b) const

	{

		return distance != b.distance  ? distance > b.distance : cost > b.cost;

	}

} P;

 

// first 最短路径，second?点?号

 

// ?

vector<edge> G[MAX_V];

 

// V是?点数

int V;

bool visited[MAX_V];

 

// 求解从?点s出?到所有点的最短花?

int dijkstra(int s)

{

	int result = 0;

	priority_queue<P, vector<P>, greater<P> > que;

	memset(visited, 0, V * sizeof(bool));

	que.push(P(0, 0, 0));

 

	while (!que.empty())

	{

		P p = que.top(); que.pop();

		int v = p.to;

		if (visited[v]) continue;

		visited[v] = true;

		result += p.cost;

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

		{

			edge e = G[v][i];

			que.push(P(G[v][i].to, p.distance + G[v][i].distance, G[v][i].cost));

		}

	}

 

	return result;

}

 

///////////////////////////SubMain//////////////////////////////////

int main(int argc, char *argv[])

{

	int /*N = V,*/ M;

	while (cin >> V >> M && V)

	{

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

		{

			G[i].clear();

		}

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

		{

			int u, v, d, c;

			cin >> u >> v >> d >> c;

			--u, --v;

			G[u].push_back(edge(v, d, c));

			G[v].push_back(edge(u, d, c));

		}

 

		cout << dijkstra(0) << endl;

	}

	return 0;

}

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

    {  

       // freopen("cin.txt","r",stdin);  

        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;  

    }