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

#include<cstdio>

#include<cstdlib>

#include<string>

#include<cstring>

#include<algorithm>

#include<queue>

#include<vector>

#define N 20100

#define M 50010

#define rg register

using namespace std;

typedef long long ll;

typedef double db;

int n,m,tot=0;

int dis[N],head[N],vis[N];

int nxt[M],to[M],w[M],c[M];

void link(int x,int y,int z,int v){

	nxt[tot]=head[x],to[tot]=y,w[tot]=z,c[tot]=v,head[x]=tot++;

}

void spfa(){

	queue <int> q;

	memset(dis,0x3f,sizeof(dis));

	memset(vis,0,sizeof(vis));

	q.push(1),dis[1]=0,vis[1]=1;

	while (!q.empty()){

		int x=q.front();q.pop();

		for (int i=head[x];i!=-1;i=nxt[i]){

			int v=to[i];

			if (dis[v]<=dis[x]+w[i]) continue;

			dis[v]=dis[x]+w[i];

			if (!vis[v]) vis[v]=1,q.push(v);

		}

		vis[x]=0;

	}

}

int main(){

//	freopen ("2249.in","r",stdin);

//	freopen ("2249.out","w",stdout);

	while (scanf ("%d%d",&n,&m)&&(n||m)){

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

		tot=0;int x,y,z,v;

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

			scanf ("%d%d%d%d",&x,&y,&z,&v);

			link(x,y,z,v),link(y,x,z,v);

		}

		spfa();

		int ans=0;

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

			int mx=2000;

			for (int j=head[i];j!=-1;j=nxt[j]){

				v=to[j];

				if (dis[i]==dis[v]+w[j]) mx=min(mx,c[j]);

			}

			ans+=mx;

		}

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

	

	}

	return 0;

}

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

#include <cstring>

#include <algorithm>

#include <queue>



using namespace std;



const int inf = 0x3f3f3f3f;

const int N = 10414;

const int M = 40414;



struct Edge{

	int u, v, d, c;

	int next;

}edge[M];



int cnt, head[N];

int op, tp, link[N];

int vis[N], dis[N], cost[N];

queue<int>q;



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

void spfa(int n);



int main(){

	int n, m, i, u, v, d, c;

	while(scanf("%d %d", &n, &m) && (n || m)){

		cnt = 0;

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

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

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

			add_edge(u, v, d, c);

			add_edge(v, u, d, c);

		}

		spfa(n);

	}

	return 0;

}

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

	edge[cnt].u = u;

	edge[cnt].v = v;

	edge[cnt].d = d;

	edge[cnt].c = c;

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

	head[u] = cnt++;

}

void spfa(int n)

{

    int v, d, c;

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

    memset(vis, 0,sizeof(vis));

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

    memset(cost, inf, sizeof(cost));

    dis[1]=0;

    cost[1]=0;

    vis[1]=true;

    q.push(1);

    while(!q.empty())

    {

        int u=q.front();

        q.pop();

        vis[u]=false;

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

        {

            v = edge[i].v;

            d = edge[i].d;

            c = edge[i].c;

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

            {

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

                cost[v] = c;

                if(!vis[v])

                {

                    q.push(v);

                    vis[v]=true;

                }

            }

        }

    }

    int sum = 0;

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

    	sum += cost[i];

    }

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

    return;

}