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

#include <string>

#include <queue>

#include <cstdio>

#include <cstring>

#include <cmath>

#include <ctype.h>

#include <map>

#include <vector>

#include <algorithm>

#include <set>

#define ll long long

using namespace std;

const int mod = 1e9 + 7;

const int N = 100000+5;

const int M = N*2;

int n,m;

typedef pair<int,int> pii;

struct Edge {

    int v, d,c;

    int next;

}edge[M];

int head[N], d[N], tot;

int cost[N];

int vis[N];

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

    edge[tot].v = v;

    edge[tot].d = d;

    edge[tot].c = c;

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

    head[u] = tot++;

}

void dij(int s) {

    priority_queue<pii, vector<pii>, greater<pii> > Q;

    for(int i = 1; i <= n; i++) d[i] = 10000000+5;

    d[s] = 0;

    cost[s] = 0;

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

    Q.push(make_pair(d[s], s));

    while(!Q.empty()) {

        pii tmp = Q.top();

        Q.pop();

        int x = tmp.second;

        if(vis[x]) continue;

        vis[x] = true;

        for(int i = head[x]; i+1; i = edge[i].next) {

            if(d[edge[i].v] > d[x] + edge[i].d) {

                d[edge[i].v] = d[x] + edge[i].d;

                cost[edge[i].v] = edge[i].c;

                Q.push(make_pair(d[edge[i].v], edge[i].v));

            }

            if(d[edge[i].v] == (d[x] + edge[i].d))

            {

                cost[edge[i].v] = min(cost[edge[i].v],edge[i].c);

            }

        }

    }

}



int main()

{

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

   {

       if(m == 0&& n ==0) break;

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

       tot = 1;

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

       {

           int u,v,d,c;

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

           addedge(u,v,d,c);

           addedge(v,u,d,c);

       }

       dij(1);

       int ans = 0;

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

       {

           ans += cost[i];

       }

       cout << ans << endl;

   }



}


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

using namespace std;

const int maxn = 2e4+9;

const int inf = 0x3f3f3f3f;

typedef long long int ll;

typedef pair<int,int> pi;

struct {

    int v,nex,d,c;

}e[maxn*2];

int in[maxn];

int dis[maxn];

int head[maxn];

int tot;

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

    e[tot] ={v,head[u],d,c};

    head[u] = tot++;

}

int dd[maxn];

priority_queue<pi> qq;

int main()

{

    int n,m;

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

            tot =0;

        if(n==0 && m==0 ) break;

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

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

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

        memset(in,0,sizeof(in));



        while(!qq.empty()){

            qq.pop();

        }

        qq.push(pi(0,1));

        dis[1] =0;

        dd[1] = 0;



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

            int u,v,d,c;

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

            addedge(u,v,d,c);

            addedge(v,u,d,c);

        }

        while(!qq.empty()){

            pi now = qq.top();

            qq.pop();

            int pp = now.second;

            if(in[pp]==1) continue;

            in[pp] = 1;

            for(int i=head[pp];i!=-1;i=e[i].nex){

                int v= e[i].v;

                int d = e[i].d;

                if(in[v]==1) continue;

                if( dis[pp]+d<dis[v]){

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

                    dd[v] = e[i].c;

                    qq.push(pi(-dis[v],v));

                }else if(dis[pp]+d==dis[v]){

                    dd[v] = min(dd[v],e[i].c);

                }

            }

        }

        int ans = 0;

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

            ans+=dd[i];

        }

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

    }

    return 0;

}