// Original C++ solution (slower):
#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;

}




// Optimized solution to the same problem (faster):
//#include<bits/stdc++.h>

#define _CRT_SBCURE_NO_DEPRECATE

#include <set>

#include <map>

#include <cmath>

#include <queue>

#include <stack>

#include <vector>

#include <string>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <iostream>

#include <algorithm>

#include <functional>

//#define UP(i,x,y) for(int i=x;i<=y;i++)

//#define DOWN(i,x,y) for(int i=x;i>=y;i--)

#define sdddd(x,y,z,k) scanf("%d%d%d%d", &x, &y, &z, &k)

#define sddd(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define sdd(x,y) scanf("%d%d", &x, &y)

#define sd(x) scanf("%d", &x)

#define mp make_pair

#define pb push_back

#define lson k<<1

#define rson k<<1|1

#define mid (l+r)/2

#define ms(x, y) memset(x, y, sizeof x)

using namespace std;

typedef long long ll;

//typedef unsigned long long ull;

#define MOD 142857

const int maxn = 10100;

const int INF = 0x3f3f3f3f;

const ll LINF = 0x3f3f3f3f3f3f3f3f;

int n, m, s, t;

int len;

struct road

{

	int u, v, len, cost;

	int next;

};

struct node

{

    int v;

    int len;

    int cost;

    node(int v, int l, int c):v(v),len(l),cost(c){}

    friend bool operator <(node a, node b)

    {

        return a.len>b.len;

    }

};

road G[maxn*5];

int h[maxn];

int mx = -INF;

int d[maxn];

int c[maxn];

int path[maxn];

void dij()

{

    fill(d, d+n+1, INF);

    fill(path, path+n+1, -1);

    fill(c, c+n+1, 0);

    d[1] = 0;

    priority_queue<node> pque;

    pque.push(node(1, 0, 0));

    while(pque.size())

    {

        node p = pque.top(); pque.pop();

        int v = p.v;

        if(d[v] < p.len) continue;

        for(int i = h[v]; i != -1; i = G[i].next)

        {

            road e = G[i];

            if(d[e.v] > d[e.u] + e.len)

            {

                d[e.v] = d[e.u] + e.len;

                c[e.v] = c[e.u] + e.cost;

                path[e.v] = i;

                pque.push(node(e.v, d[e.v], c[e.v]));

            }

            else if(d[e.v] == d[e.u] + e.len)

            {

                if(path[e.v] != -1 && G[path[e.v]].cost > e.cost)

                {

                    path[e.v] = i;

                    pque.push(node(e.v, d[e.v], c[e.v]));

                }

            }

        }

    }

}

int main()

{

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

    while(~sdd(n, m) && (n||m))

    {

        int ta, tb, tc, td;

        int len = 0;

        fill(h, h+n+1, -1);

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

        {

            sdddd(ta, tb, tc, td);

            G[len].u = ta;

            G[len].v = tb;

            G[len].len = tc;

            G[len].cost = td;

            G[len].next = h[ta];

            h[ta] = len++;



            G[len].u = tb;

            G[len].v = ta;

            G[len].len = tc;

            G[len].cost = td;

            G[len].next = h[tb];

            h[tb] = len++;

        }

        dij();

        int ans = 0;

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

        {

            if(path[i]!=-1)

            {

                ans += G[path[i]].cost;

            }

        }

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

    }



	return 0;

}




// Fastest known solution for this problem: