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

using namespace std;



typedef long long ll;

const int N = 10005;

const int M = 1000000007;



int n, m;

typedef int wtype;

struct Edge { int v; wtype d, c; };

vector<Edge> e[N];

wtype dist[N], cost[N];

int pre[N];

bool vis[N];

int SPFA(int src) {

  memset(dist, 0x3f, sizeof(dist)); dist[src] = 0;

  memset(cost, 0x3f, sizeof(cost)); cost[src] = 0;

  memset(vis, 0, sizeof(vis)); vis[src] = true;

  stack<int> que; que.push(src);

  while (!que.empty()) {

    int u = que.top(); que.pop();

    vis[u] = false;

    for (int i = 0; i < (int)e[u].size(); i++) {

      int v = e[u][i].v; wtype d = e[u][i].d, c = e[u][i].c;

      if (dist[v] > dist[u] + d || (dist[v] == dist[u] + d && cost[v] != 0x3f3f3f3f && cost[v] > c)) {

        dist[v] = dist[u] + d; cost[v] = c;

        if (!vis[v]) { vis[v] = true; que.push(v); }

      }

    }

  }

  int ret = 0;

  for (int i = 1; i <= n; i++) { ret += cost[i]; }

  return ret;

}



int main() {

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

    for (int i = 1; i <= n; i++) { e[i].clear(); }

    for (int i = 0, u, v, d, c; i < m; i++) {

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

      e[u].push_back((Edge) {v, d, c});

      e[v].push_back((Edge) {u, d, c});

    }

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

  }

}

// Faster C++ solution for the same problem (measured speedup: 1.2890293234904535x):
    #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;  

    }