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

#include <stdio.h>

#include <string.h>

#include <queue>

using namespace std;

const int maxn=10050,maxm=20050,inf=0x3f3f3f3f;

struct Edge

{

    int to,next,dis,cos ;

}edge[maxm*2];

struct Pair

{

    int D,V,C;

    Pair(){;}

    Pair(int d,int c,int v)

    {

        D=d,V=v,C=c;

    }

    friend bool operator <(const Pair a,const Pair b)

    {

        if(a.D!=b.D)

        return a.D>b.D;

        else return a.C>b.C;

    }

};

int tot,head[maxn],dist[maxn],cost[maxn];

bool vis[maxn];

void init()

{

    tot=0;

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

}

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

{

    edge[tot].to=v;

    edge[tot].dis=d;

    edge[tot].cos=c;

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

    head[u]=tot++;

}

int dijstra(int start)

{

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

    memset(dist,inf,sizeof(dist));

    int ans=0;

    dist[start]=0;

   // vis[start]=true;

    priority_queue<Pair>que;

    que.push(Pair(0,0,start));

    while(!que.empty())

    {

        Pair now=que.top();

        que.pop();

        if(vis[now.V])

            continue;

        vis[now.V]=true;

        ans+=now.C;

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

        {

            int to=edge[i].to;

            que.push(Pair(now.D+edge[i].dis,edge[i].cos,to));

        }

    }

    return ans;

}

int main()

{

    int u,v,d,c;

    int n,m;

    while(scanf("%d%d",&n,&m)!=-1)

    {

        init();

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

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

        {

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

            add_edge(u,v,d,c);

            add_edge(v,u,d,c);

        }

        printf("%d\n",dijstra(1));

    }

    return 0;

}

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

#include <cstring>

#include <queue>

using namespace std;

const int INF = 0x3f3f3f3f;

struct node

{

    int to, w, c, next;

} edge[50005];

int head[10005], ip, cost[10005], dis[10005], n, m;

bool vis[10005];

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

{

    edge[ip].to = v;

    edge[ip].w = d;

    edge[ip].c = c;

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

    head[u] = ip++;

}

void spfa(int s)

{

    queue<int> q;

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

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

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

    dis[s] = 0;

    cost[s] = 0;

    vis[s] = 1;

    q.push(s);

    while (!q.empty())

    {

        int u = q.front();

        q.pop();

        vis[u] = 0;

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

        {

            int to = edge[i].to;

            int w = edge[i].w;

            if(dis[to] > dis[u] + w||(dis[to] == dis[u]+w&&cost[to] > edge[i].c))

            {

                dis[to] = dis[u] + w;

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

                if(!vis[to])

                {

                    q.push(to);

                    vis[to] = 1;

                }

            }

        }

    }

}

int main()

{

    while (scanf("%d %d", &n, &m) != EOF)

    {

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

            break;

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

        ip = 0;

        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);

        }

        spfa(1);

        int ans = 0;

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

            ans += cost[i];

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

    }

    return 0;

}