// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define inf 0x3f3f3f3f

const int maxn = 10000+5;

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

struct edge

{

    int v,d,c;

    edge(int A,int B,int C):v(A),d(B),c(C) {}

};

vector<edge> G[maxn];

queue<int> que;



void spfa()

{

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

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

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

    vis[1] = 1;

    dis[1] = 0;

    cost[1] = 0;

    que.push(1);

    while(!que.empty())

    {

        int u = que.front();

        que.pop();

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

        {

            edge &e = G[u][i];

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

            {

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

                cost[e.v] = e.c;

                if(!vis[e.v])

                {

                    vis[e.v] = 1;

                    que.push(e.v);

                }

            }

            else if(dis[e.v] == dis[u] + e.d && cost[e.v] > e.c)

            {

                cost[e.v] = e.c;

                if(!vis[e.v])

                {

                    vis[e.v] = 1;

                    que.push(e.v);

                }

            }

        }

        vis[u] = 0;

    }

    int ans = 0;

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

    ans += cost[i];

    cout << ans << endl;

}





//void spfa()

//{

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

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

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

//    vis[1] = 1;

//    dis[1] = 0;

//    cost[1] = 0;

//    que.push(1);

//    while(!que.empty())

//    {

//        int u = que.front();

//        que.pop();

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

//            {

//            edge &e = G[u][i];

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

//            {

//                dis[e.v] = dis[u] + e.d;

//                cost[e.v] = e.c;

//                if(!vis[e.v])

//                {

//                    vis[e.v] = 1;

//                    que.push(e.v);

//                }

//            }

//            else if(dis[e.v] == dis[u] + e.d && cost[e.v] > e.c)

//            {

//                cost[e.v] = e.c;

//                if(!vis[e.v])

//                {

//                    vis[e.v] = 1;

//                    que.push(e.v);

//                }

//            }

//        }

//        vis[u]=0;

//    }

//    int ans = 0;

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

//        ans+=cost[i];

//    cout<<ans<<endl;

//}



int main()

{

    while(cin>>N>>M)

    {

        if(N==0&&M==0)

            break;

        int u,v,d,c;

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

        {

            cin>>u>>v>>d>>c;

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

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

        }

        spfa();

//        /// clear

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

            G[i].clear();

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4331327660898465x):
//#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;

}