// Slower C++ solution:
#pragma comment(linker, "/STACK:102400000,102400000")

//#include <bits/stdc++.h>

#include <iostream>

#include <iomanip>

#include <cstdio>

#include <cmath>

#include <cstring>

#include <climits>

#include <stdlib.h>

#include <deque>

#include <queue>

#include <stack>

#include <algorithm>

#include <list>

#include <map>

#include <set>

#include <utility>

#include <sstream>

#include <complex>

#include <string>

#include <vector>

#include <bitset>

#include <complex>

#include <functional>

#include <fstream>

#include <ctime>

#include <stdexcept>

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))

#define pb push_back

#define mp make_pair

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int,int> P;

const int INF = 0x3f3f3f3f;

const int maxn = 1e5+5;

const int mod = 1e6;

const double eps = 1e-8;

const double pi = asin(1.0)*2;

const double e = 2.718281828459;

bool Finish_read;

template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}



struct ac {

	int v;

	int dis;

	int cost;

};



int n, m;

int a, b, d, c;

int ans;

int dis[maxn];

int cost[maxn];

bool vis[maxn];

vector<ac> Adj[maxn];



void Dijkstra() {

	mem(dis, INF);

	mem(cost, INF);

	mem(vis, 0);

	dis[1] = 0;

	cost[1] = 0;

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

		int u = -1, dismin = INF, costmin = INF;

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

			if (!vis[j]) {

				if (dis[j] < dismin) {

					u = j;

					dismin = dis[j];

					costmin = cost[j];

				}

				else if (dis[j] == dismin) {

					if (cost[j] < costmin) {

						u = j;

						dismin = dis[j];

						costmin = cost[j];

					}

				}

			}

		}

		if (u == -1) {

			return;

		}

		vis[u] = 1;

		for (int j = 0; j < int(Adj[u].size()); ++j) {

			int v = Adj[u][j].v;

			if (!vis[v]) {

				if (dis[u] + Adj[u][j].dis < dis[v]) {

					dis[v] = dis[u] + Adj[u][j].dis;

					cost[v] = Adj[u][j].cost;

				}

				else if (dis[u] + Adj[u][j].dis == dis[v]) {

					if (Adj[u][j].cost < cost[v]) {

						cost[v] = Adj[u][j].cost;

					}

				}

			}

		}

	}

}



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

//#ifndef ONLINE_JUDGE

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

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

//#endif

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

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

			read(a); read(b); read(d); read(c);

			ac add;

			add.v = b;

			add.dis = d;

			add.cost = c;

			Adj[a].pb(add);

			add.v = a;

			Adj[b].pb(add);

		}

		Dijkstra();

		ans = 0;

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

			Adj[i].clear();

//			printf("dis[%d]=%d cost[%d]=%d\n", i, dis[i], i, cost[i]);

			ans += cost[i];

		}

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

	}

//#ifndef ONLINE_JUDGE

//	fclose(stdin);

//	fclose(stdout);

//	system("gedit out.txt");

//#endif

    return 0;

}




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

#include<string.h>  

#include<math.h>  

  

//#include<map>   

//#include<set>

#include<deque>  

#include<queue>  

#include<stack>  

#include<bitset> 

#include<string>  

#include<iostream>  

#include<algorithm>  

using namespace std;  

  

#define ll long long  

#define INF 0x3f3f3f3f  

#define mod 1000000

#define clean(a,b) memset(a,b,sizeof(a))// 水印 

//spfa

//https://cn.vjudge.net/contest/239171#problem/C 



using namespace std;

//const int maxn=10005;

const int inf=0x3f3f3f3f;

int N,M,k;

int head[10100],cost[10100],dis[10100];

bool vst[10100];

struct node{

    int to,next,dis,cost;

}edge[50100];

void addEdge(int a,int b,int dis,int cost)

{

    edge[k].to=b;

    edge[k].dis=dis;

    edge[k].cost=cost;

    edge[k].next=head[a];

    head[a]=k;

    k++;

}

void spfa(int x)

{

	clean(dis,INF);

	clean(vst,0);

	clean(cost,INF);

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

//    memset(vst,0,sizeof(vst));

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

    queue<int> q;

    dis[x]=0;

    cost[x]=0;

    q.push(x);

    while(!q.empty())

	{

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

        vst[x]=0;

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

		{

            node b=edge[i];

            if(dis[b.to]>dis[x]+b.dis)

			{

                if(!vst[b.to])

				{

                    vst[b.to]=1;

                    q.push(b.to);

                }

                dis[b.to]=dis[x]+b.dis;

                cost[b.to]=b.cost;

            }

			else if(dis[b.to]==dis[x]+b.dis)

			{

                if(cost[b.to]>b.cost)

                    cost[b.to]=b.cost;

            }

        }

    }

}



int main()

{

    while(cin>>N>>M,N)

	{

        clean(head,-1);

        k=0;

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

            int a,b,d,c;

            cin>>a>>b>>d>>c;

            addEdge(a,b,d,c);

            addEdge(b,a,d,c);

        }

        spfa(1);

        long long re=0;

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

            re+=cost[i];

        }

        cout<<re<<endl;

    }



    return 0;

}