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

#include <queue>

#include <cstdio>

#include <algorithm>

#include <cstring>

using namespace std;

struct sdsd

{

    int from,to,value,time;

};

bool operator < (sdsd a,sdsd b)

{

    return a.time>b.time;

}

sdsd zz[45555];

int sb[15555],sc[15555],svalue[15555],stime1[155555],sd[15555];

int main ()

{

    //freopen ("data.in","r",stdin);

    int n,m;

    while (cin >>n>>m)

    {

        if (!n) break;

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

        {

            svalue[i]=1e9+1;

            stime1[i]=1e9+1;

        }

        svalue[1]=0;

        stime1[1]=0;

        memset (sc,0,sizeof(sc));

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

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

        memset (sd,0,sizeof(sd));

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

        {

            int a,b,c,d;

            scanf ("%d%d%d%d",&a,&b,&c,&d);

            zz[2*i].to=a;

            zz[2*i].from=sb[b];

            sb[b]=2*i;

            zz[2*i].value=d;

            zz[2*i].time=c;

            zz[2*i+1].to=b;

            zz[2*i+1].from=sb[a];

            sb[a]=2*i+1;

            zz[2*i+1].value=d;

            zz[2*i+1].time=c;

        }

        priority_queue <int > se;

        int x=sb[1];

        while (x!=-1)

        {

            if (stime1[1]+zz[x].time<stime1[zz[x].to])

            {

                stime1[zz[x].to]=stime1[1]+zz[x].time;

                svalue[zz[x].to]=zz[x].value;

                sd[zz[x].to]=1;

                if (!sc[zz[x].to])

                {

                    se.push(zz[x].to);

                    sc[zz[x].to]=1;

                }

            }

            else if (stime1[1]+zz[x].time==stime1[zz[x].to])

            {

                if (zz[x].value<svalue[zz[x].to])

                {

                    svalue[zz[x].to]=zz[x].value;

                    sd[zz[x].to]=1;

                    if (!sc[zz[x].to])

                    {

                        se.push(zz[x].to);

                        sc[zz[x].to]=1;

                    }

                }

            }

            x=zz[x].from;

        }

        while (!se.empty())

        {

            int tt=se.top();

            se.pop();

            sc[tt]=0;

            int t=sb[tt];

        while (t!=-1)

        {

            if (stime1[tt]+zz[t].time<stime1[zz[t].to])

            {

                stime1[zz[t].to]=stime1[tt]+zz[t].time;

                svalue[zz[t].to]=zz[t].value;

                sd[zz[t].to]=tt;

                //cout <<zz[x].to<<" "<<sd[zz[x].to]<<endl;

                if (!sc[zz[t].to])

                {

                    se.push(zz[t].to);

                    sc[zz[t].to]=1;

                }

            }

            else if (stime1[tt]+zz[t].time==stime1[zz[t].to])

            {

            /*cout <<tt<<" "<<zz[t].to<<endl;

            cout<<svalue[tt]<<" "<< zz[t].value<<" "<<svalue[zz[t].to]<<endl;

            cout <<endl;*/

                if (zz[t].value<svalue[zz[t].to])

                {

                    svalue[zz[t].to]=zz[t].value;

                    sd[zz[t].to]=tt;

                    if (!sc[zz[t].to])

                    {

                        se.push(zz[t].to);

                        sc[zz[t].to]=1;

                    }

                }

            }

            t=zz[t].from;

        }



        }

        int s=0;

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

        {

            s+=svalue[i];

        }

        cout <<s<<endl;

    }

}




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

#include <string>

#include <queue>

#include <cstdio>

#include <cstring>

#include <cmath>

#include <ctype.h>

#include <map>

#include <vector>

#include <algorithm>

#include <set>

#define ll long long

using namespace std;

const int mod = 1e9 + 7;

const int N = 100000+5;

const int M = N*2;

int n,m;

typedef pair<int,int> pii;

struct Edge {

    int v, d,c;

    int next;

}edge[M];

int head[N], d[N], tot;

int cost[N];

int vis[N];

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

    edge[tot].v = v;

    edge[tot].d = d;

    edge[tot].c = c;

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

    head[u] = tot++;

}

void dij(int s) {

    priority_queue<pii, vector<pii>, greater<pii> > Q;

    for(int i = 1; i <= n; i++) d[i] = 10000000+5;

    d[s] = 0;

    cost[s] = 0;

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

    Q.push(make_pair(d[s], s));

    while(!Q.empty()) {

        pii tmp = Q.top();

        Q.pop();

        int x = tmp.second;

        if(vis[x]) continue;

        vis[x] = true;

        for(int i = head[x]; i+1; i = edge[i].next) {

            if(d[edge[i].v] > d[x] + edge[i].d) {

                d[edge[i].v] = d[x] + edge[i].d;

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

                Q.push(make_pair(d[edge[i].v], edge[i].v));

            }

            if(d[edge[i].v] == (d[x] + edge[i].d))

            {

                cost[edge[i].v] = min(cost[edge[i].v],edge[i].c);

            }

        }

    }

}



int main()

{

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

   {

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

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

       tot = 1;

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

       }

       dij(1);

       int ans = 0;

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

       {

           ans += cost[i];

       }

       cout << ans << endl;

   }



}