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



using namespace std;

const int N = 1E4 + 7;

bool vis[N];

int n, m;

typedef struct node

{

   int to,dis,cost;

   node(){}

   node(int a,int b,int c) : to(a),dis(b),cost(c) {}

   bool operator < (const node &a) const {

       return dis == a.dis ? cost > a.cost : dis > a.dis;

   }

}P;

vector<P>g[N];

int dij()

{

    int ans = 0;

    priority_queue<P> pq;

    pq.push(P(1,0,0));

    while(!pq.empty()) {

        P now = pq.top() ; pq.pop();

        if(vis[now.to]) continue;

        vis[now.to] = true;

        ans += now.cost;

        for(int i = 0;i < g[now.to].size();i ++) {

            P temp = g[now.to][i];

            pq.push(P(temp.to, now.dis + temp.dis, temp.cost));

        }

    }

    return ans;

}

int main()

{

   // freopen("f:\\jj.txt","r",stdin);

    std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

    while(cin >> n >> m) {

        if(n + m == 0)  break;

        for(int i = 1;i <= n;i ++)  g[i].clear();

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

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

            int a,b,c,d;

            cin >> a >> b >> c >> d;

            g[a].push_back(P(b,c,d));

            g[b].push_back(P(a,c,d));

        }

        cout << dij() << endl;

    }

    return 0;

}

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

    #include <string.h>  

    #include <queue>  

    #include <iostream>  

    #include <algorithm>  

    using namespace std;  

    const int maxn=10050;  

    const int maxe=2005000;  

    const int INF=1e9;  

    struct note  

    {  

        int to;  

        int w;  

        int c;  

        int next;  

    };  

    note edge[maxe];  

    int head[maxn];  

    int ip;  

    void init()  

    {  

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

        ip=0;  

    }  

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

    {  

        edge[ip].to=v;  

        edge[ip].c=c;  

        edge[ip].w=w;  

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

        head[u]=ip++;  

    }  

    int cost[maxn];  

    int dis[maxn];  

    bool vis[maxn];  

    queue<int>q;  

    void spfa(int s,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[s]=0;  

        cost[s]=0;  

        vis[s]=true;  

        q.push(s);  

        while(!q.empty())  

        {  

            int u=q.front();  

            q.pop();  

            vis[u]=false;  

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

            {  

                int to=edge[i].to;  

                int val=edge[i].w;  

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

                {  

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

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

                    if(!vis[to])  

                    {  

                        q.push(to);  

                        vis[to]=true;  

                    }  

                }  

            }  

        }  

    }  

    int main()  

    {  

       // freopen("cin.txt","r",stdin);  

        int n,m;  

        int u,v,w,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,&w);  

                addedge(u,v,c,w);  

                addedge(v,u,c,w);  

            }  

            spfa(1,n);  

            int ans=0;  

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

                ans+=cost[i];  

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

        }  

        return 0;  

    }