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

#include <cstdio>

#include <cstring>

#include <vector>

#include <queue>

using namespace std;

const int INF = 0x3f3f3f3f;

const int MAXN = 10005;

struct Edge

{

    int to, w, cost;

    Edge() {}

    Edge(int a, int b, int c): to(a), w(b), cost(c) {}

    bool operator < (const Edge &r) const

    {

        return w > r.w || w == r.w && cost > r.cost;

    }

};

vector<Edge> G[MAXN];

bool vis[MAXN];

int dist[MAXN];

int cost[MAXN];

int pre[MAXN];

void Dijkstra(int n, int start)

{

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

        vis[i] = 0, dist[i] = cost[i] = INF;

    priority_queue<Edge> que;

    que.push(Edge(start, 0, 0));

    dist[start] = cost[start] = 0;

    pre[start] = start;

    Edge tmp;

    while (!que.empty())

    {

        tmp = que.top();

        que.pop();

        int u = tmp.to;

    //    cout << tmp.to << endl;

        if (vis[u]) continue;

        vis[u] = 1;

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

        {

            int v = G[u][i].to;

            int w = G[u][i].w;

    //        cout << v << " " << w << " " << G[u][i].cost << endl;

    //        cout << dist[v] << " " << cost[v] << endl;

     //       cout << dist[u] << " " << cost[u] << endl;

            if (!vis[v] && dist[v] > dist[u] + w)

            {

                dist[v] = dist[u] + w;

                cost[v] = G[u][i].cost;

      //          cout <<"s1  " << v << " " << dist[v] << " " << cost[v] << endl;

                pre[v] = u;

                que.push(Edge(v, dist[v], cost[v]));

            }

            else if (!vis[v] && dist[v] == dist[u]+w && cost[v] >  G[u][i].cost)

            {

                cost[v] = G[u][i].cost;

         //       cout << "s2  " <<  v << " " << dist[v] << " " << cost[v] << endl;

                pre[v] = u;

                que.push(Edge(v, dist[v], cost[v]));

            }

        }

    }

   // for (int i = 2; i <= n; i++) cout << cost[i] - cost[pre[i]] <<endl;

}

int n, m;

int main()

{

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

    {

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

            G[i].clear();

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

        {

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

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

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

        }

        Dijkstra(n, 1);

        int ans = 0;

        for (int i = 2; i <= n; i++) ans += cost[i];

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

    }

}

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

using namespace std;



#define db double

#define ll long long

#define RG register



inline int gi()

{

	RG int ret; RG bool flag; RG char ch;

	ret=0, flag=true, ch=getchar();

	while (ch < '0' || ch > '9')

		ch == '-' ? flag=false : 0, ch=getchar();

	while (ch >= '0' && ch <= '9')

		ret=(ret<<3)+(ret<<1)+ch-'0', ch=getchar();

	return flag ? ret : -ret;

}



const db pi = acos(-1.0);

const int N = 142857, inf = 1<<30;



int f[N],et[N],ed[N],nx[N],ew[N],dis[N],cst[N];

bool vis[N];

queue <int> q;

int num;



inline void add(int x,int y,int z,int w)

{

	et[++num]=y, nx[num]=f[x], ed[num]=z, ew[num]=w, f[x]=num;

}



int main()

{

	int n,m,i,x,y,z,w;

	while (true)

		{

			n=gi(), m=gi();

			if (n == 0)

				break;

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

				{

					x=gi(), y=gi(), z=gi(), w=gi();

					add(x,y,z,w), add(y,x,z,w);

				}

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

				cst[i]=dis[i]=inf;

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

			while (!q.empty())

				{

					x=q.front(), q.pop(), vis[x]=false;

					for (i=f[x]; i; i=nx[i])

						{

							y=et[i], z=ed[i], w=ew[i];

							if (dis[y] > dis[x]+z)

								{

									dis[y]=dis[x]+z;

									cst[y]=cst[x]+w;

									if (!vis[y])

										q.push(y), vis[y]=true;

								}

							if (dis[y] == dis[x]+z && cst[y] > w)

								cst[y]=w;

						}

				}

			x=0;

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

				x+=cst[i];

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

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

				f[i]=0;

			num=0;

		}

	return 0;

}