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

#include <algorithm>

#include <cstdio>

#include <queue>

#include <cstring>

#define INF 0x3f3f3f



using namespace std;

const int MAX_V=100001;

struct node

{

    int to, dis, cost, next;

}edge[MAX_V];



int head[MAX_V], d[MAX_V], mcost[MAX_V];//mcoat一个?点??一条?

bool vis[MAX_V];

int n, m, cnt;



void add_edge(int u, int v, int d, int c)

{

    edge[cnt].to=v;

    edge[cnt].dis=d;

    edge[cnt].cost=c;

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

    head[u]=cnt++;

}



int spfa(int x)

{

    d[x]=0;         //必?！！！

    queue<int> que;

    que.push(x);

    vis[x]=true;

    while(!que.empty())

    {

        int u=que.front();

        que.pop();

        vis[u]=false;

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

        {

            node e = edge[i];

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

            {

                mcost[e.to]=e.cost;     ////??最小花?

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

                if(!vis[e.to])

                {

                    que.push(e.to);

                    vis[e.to]=true;

                }

            }

            else if(d[u]+e.dis==d[e.to] && e.cost<mcost[e.to])   ////??最小花?

                {

                    mcost[e.to]=e.cost;

                }

        }

    }

    int ans=0;

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

    {

     //   printf("\n%d\n", mcost[i]);

        ans+=mcost[i];

    }

    return ans;

}



int main()

{

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

    {

        cnt=0;          //从0?始！！！

        memset(head, -1, sizeof(head)); //初始化在前面！！！！

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

        {

            int u, v, d, c;

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

            add_edge(u,v,d,c);

            add_edge(v,u,d,c);      //双向的路！！！

        }



        //初始化

        memset(mcost, 0, sizeof(mcost));

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

        fill(vis, vis+n+1, false);



        int ans=spfa(1);

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

    }



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.6131442991623641x):
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<vector>

#include<queue>

#define MAX_V 10006

#define INF 0x3fffffff

using namespace std;

struct edge{

    int to,cost,dis;

    };

typedef pair<int,int> P;

int V;

vector<edge> G[MAX_V];

int d[MAX_V];



void dij(int s){

    priority_queue<P,vector<P>,greater<P> > que;

    fill(d,d+V,INF);

    d[s]=0;

    que.push(P(0,s));

    while(!que.empty()){

        P p=que.top();que.pop();

        int v=p.second;

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

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

            edge e=G[v][i];

            if(d[e.to]>d[v]+e.cost){

                d[e.to]=d[v]+e.cost;

                que.push(P(d[e.to],e.to));

            }

        }

    }

    int ans=0;



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

        int mimcost=INF;

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

            if(d[G[i][j].to]+G[i][j].cost==d[i]&&G[i][j].dis<mimcost){



                mimcost=G[i][j].dis;

                //cout<<mimcost<<endl;

            }

        }

        //cout<<mimcost<<endl;

        ans+=mimcost;

    }

    cout<<ans<<endl;



}



int main(){

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

    int M;

    while(cin>>V>>M){

        if(V==0&&M==0)break;

        for(int i=0;i<V;i++)G[i].clear();

        while(M--){

            int a,b,t,c;

            cin>>a>>b>>t>>c;

            a--;b--;

            edge tmp;

            tmp.to=b;

            tmp.cost=t;

            tmp.dis=c;

            G[a].push_back(tmp);

            tmp.to=a;

            G[b].push_back(tmp);

        }

        dij(0);

    }

    return 0;

}