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

#include <cstring>

#include <queue>

#define inf 0x3f3f3f3f

#define maxm 10005

#define maxn 40005



using namespace std;



int m,n;

long long edgenum,head[maxm],dis[maxm],num[maxm],ans;

bool vis[maxm];



struct node

{

    int from,to,len,cost,next;

}edge[maxn];



void init()

{

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

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

    memset(dis,inf,sizeof(dis));

    memset(num,inf,sizeof(num));

    edgenum=0;

}



void add(int u,int v,int len,int cost)

{

    node tp={u,v,len,cost,head[u]};

    edge[edgenum]=tp;

    head[u]=edgenum++;

}



long long SPFA(int st)

{

     queue<int> q;

     q.push(st);

     vis[st]=1;

     dis[st]=0;

     num[st]=0;

     ans=0;

     while(!q.empty())

     {

          int tmp=q.front();

          q.pop();

          vis[tmp]=0;

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

          {

                if((dis[edge[i].to]>dis[tmp]+edge[i].len)||((dis[edge[i].to]==dis[tmp]+edge[i].len)&&(num[edge[i].to]>edge[i].cost)))

                {

                    dis[edge[i].to]=dis[tmp]+edge[i].len;

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

                    if(!vis[edge[i].to])

                    {

                        q.push(edge[i].to);

                        vis[edge[i].to]=1;

                    }

                }

          }

     }

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

        ans+=num[i];

     return ans;

}



int main()

{

    int u,v,len,cost;

    while(cin>>m>>n&&m)

    {

        init();

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

        {

            cin>>u>>v>>len>>cost;

            add(u,v,len,cost);

            add(v,u,len,cost);

        }

        cout<<SPFA(1)<<endl;

    }

    return 0;

}

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

#include <cstdio>

#include <cstring>

#include <queue>

using namespace std;

const int inf =0x3f3f3f3f;

const int MAXN=10005;

struct node

{

    int next, to, d, c;

} G[2000005];

int cur, n;

bool vis[MAXN];

int cost[MAXN];

int dist[MAXN];

int head[MAXN];

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

{

    G[cur].to=v;

    G[cur].c=c;

    G[cur].d=d;

    G[cur].next=head[u];

    head[u]=cur++;

}

queue<int>q;

void spfa(int s)

{



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

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

    fill(cost+1,cost+n+1,inf);

    fill(dist+1,dist+n+1,inf);

    q.push(s);

    dist[s]=0;

    cost[s]=0;

    while(!q.empty())

    {

        int u=q.front();

        q.pop();

        vis[u]=false;

        for(int i=head[u]; ~i; i=G[i].next)

        {

            int v=G[i].to;

            if(dist[v]>dist[u]+G[i].d||(dist[v]==dist[u]+G[i].d&&cost[v]>G[i].c))

            {

                dist[v]=dist[u]+G[i].d;

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

                if(!vis[v])

                {

                    vis[v]=true;

                    q.push(v);

                }

            }

        }

    }

}

int main()

{

    int m;

    int u, v, d, c;

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

    {

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

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

        cur=0;

        while(m--)

        {

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

            add(u, v, d, c);

            add(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;

}