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



using namespace std;

typedef pair<int, int> P;

typedef long long ll;



const int maxv = 10000 + 10;

struct edge

{

    int to, d, c;

    edge() {}

    edge(int to, int d, int c):to(to), d(d), c(c) {}

};

vector<edge> G[maxv];

int d[maxv];



int N, M;



void dijkstra(int s)

{

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

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

    d[s] = 0;

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

    while(!que.empty())

    {

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

        int v = p.second;

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

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

        {

            edge e = G[v][i];

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

            {

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

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

            }

        }

    }

}



int main()

{

    while(scanf("%d%d", &N, &M)==2 && N)

    {

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

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

        {

            int u, v, d, c;

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

            u--; v--;

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

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

        }

        dijkstra(0);

        int ans = 0;

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

        {

            int mincost = 0x3f3f3f3f;

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

            {

                edge e = G[i][j];

                if(d[e.to]+e.d==d[i] && e.c<mincost)

                    mincost = e.c;

            }

            ans += mincost;

        }

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

    }

    return 0;

}

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

#include <string.h>

#include <queue>

#include <iostream>

#include <algorithm>

using namespace std;

const int maxn=10050;

const int maxe=40414;

const int INF=0x3f3f3f3f;

struct note

{

    int v;

    int d;

    int c;

    int next;

};

note edge[maxe];

int head[maxn];

int cnt;

void init()

{

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

    cnt=0;

}

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

{

    edge[cnt].v=v;

    edge[cnt].c=c;

    edge[cnt].d=d;

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

    head[u]=cnt++;

}

int cost[maxn];

int dis[maxn];

bool vis[maxn];

queue<int>q;

void spfa(int n)

{

    while(!q.empty())q.pop();

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

        cost[i]=dis[i]=INF;

    memset(vis,false,sizeof(vis));

    dis[1]=0;

    cost[1]=0;

    vis[1]=true;

    q.push(1);

    while(!q.empty())

    {

        int u=q.front();

        q.pop();

        vis[u]=false;

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

        {

            int v=edge[i].v;

            int val=edge[i].d;

            if(dis[v]>dis[u]+val||(dis[v]==dis[u]+val&&cost[v]>edge[i].c))//有多条最短路时，取花费最小的

            {

                dis[v]=dis[u]+val;

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

                if(!vis[v])

                {

                    q.push(v);

                    vis[v]=true;

                }

            }

        }

    }

}

int main()

{

    int n,m;

    int u,v,d,c;

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

    {

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

        init();

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

        {

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

            addedge(u,v,c,d);

            addedge(v,u,c,d);

        }

        spfa(n);

        int ans=0;

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

            ans+=cost[i];

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

    }

    return 0;

}