// 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.2053015573819919x):
#include <stdio.h>

#include <string.h>

#include <queue>

#include <iostream>

#include <algorithm>

using namespace std;

const int maxn=10050;

const int maxe=40414;

const int INF=0x3f3f3f3f;

struct note

{

    int v;

    int d;

    int c;

    int next;

};

note edge[maxe];

int head[maxn];

int cnt;

void init()

{

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

    cnt=0;

}

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

{

    edge[cnt].v=v;

    edge[cnt].c=c;

    edge[cnt].d=d;

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

    head[u]=cnt++;

}

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 v=edge[i].v;

            int val=edge[i].d;

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

            {

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

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

                if(!vis[v])

                {

                    q.push(v);

                    vis[v]=true;

                }

            }

        }

    }

}

int main()

{

    int n,m;

    int u,v,d,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,&d);

            addedge(u,v,c,d);

            addedge(v,u,c,d);

        }

        spfa(1,n);

        int ans=0;

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

            ans+=cost[i];

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

    }

    return 0;

}