// 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.4548233726634303x):
#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;

}