// 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.2901404079525072x):
#include <cstdio>

#include <cstdlib>

#include <iostream>

#include <cstring>

#include <cmath>

#include <ctime>

#include <algorithm>

#include <vector>

#include <set>

#include <queue>

#include <map>

#include <stack>

#include <bitset>

using namespace std;

typedef int gitype;

gitype gi () {

    gitype ret=0; char ch=getchar();

    while((ch<'0' || ch>'9') && ch!='-') ch=getchar();

    char c=ch=='-'?getchar():ch;

    while(c>='0' && c<='9') ret=ret*10+c-'0',c=getchar();

    return ch=='-'?-ret:ret;

}

const int N = 10010;

const int M = 100010;

int n,m,st[N],vis[N],dis[N],pt[M],nxt[M],w[M],c[M],cost[N],ent=0;

void link (int u,int v,int _w,int _c) {

    pt[++ent]=v; nxt[ent]=st[u]; st[u]=ent; w[ent]=_w; c[ent]=_c;

    pt[++ent]=u; nxt[ent]=st[v]; st[v]=ent; w[ent]=_w; c[ent]=_c;

}

queue<int> q;

int main () {

    while(scanf("%d%d",&n,&m)==2 && (n || m)) {

        memset(st,0,sizeof(st)); ent=0;

        int u,v,_w,_c;

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

            u=gi(); v=gi(); _w=gi(); _c=gi(); link(u,v,_w,_c);

        }

        for(int i=1;i<=n;i+=1) dis[i]=1e9 + 5;

        dis[1]=0; q.push(1);

        while(!q.empty()) {

            int r=q.front(); q.pop(); vis[r]=false;

            for(int i=st[r];i;i=nxt[i]) {

                if(dis[pt[i]] > dis[r]+w[i]) {

                    dis[pt[i]] = dis[r]+w[i]; cost[pt[i]] = c[i];

                    if(!vis[pt[i]]) {

                        vis[pt[i]] = true; q.push(pt[i]);

                    }

                } else if(dis[pt[i]] == dis[r]+w[i]) {

                    cost[pt[i]] = min(cost[pt[i]], c[i]);

                }

            }

        }

        int ans = 0;

        for(int i=2;i<=n;i+=1) ans += cost[i];

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

    }

    return 0;

}