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

#include <algorithm>

#include <cstdio>

#include <queue>

#include <cstring>

#define INF 0x3f3f3f



using namespace std;

const int MAX_V=100001;

struct node

{

    int to, dis, cost, next;

}edge[MAX_V];



int head[MAX_V], d[MAX_V], mcost[MAX_V];//mcoat一个?点??一条?

bool vis[MAX_V];

int n, m, cnt;



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

{

    edge[cnt].to=v;

    edge[cnt].dis=d;

    edge[cnt].cost=c;

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

    head[u]=cnt++;

}



int spfa(int x)

{

    d[x]=0;         //必?！！！

    queue<int> que;

    que.push(x);

    vis[x]=true;

    while(!que.empty())

    {

        int u=que.front();

        que.pop();

        vis[u]=false;

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

        {

            node e = edge[i];

            if(d[e.to] > d[u]+e.dis)

            {

                mcost[e.to]=e.cost;     ////??最小花?

                d[e.to] = d[u]+e.dis;

                if(!vis[e.to])

                {

                    que.push(e.to);

                    vis[e.to]=true;

                }

            }

            else if(d[u]+e.dis==d[e.to] && e.cost<mcost[e.to])   ////??最小花?

                {

                    mcost[e.to]=e.cost;

                }

        }

    }

    int ans=0;

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

    {

     //   printf("\n%d\n", mcost[i]);

        ans+=mcost[i];

    }

    return ans;

}



int main()

{

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

    {

        cnt=0;          //从0?始！！！

        memset(head, -1, sizeof(head)); //初始化在前面！！！！

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

        {

            int u, v, d, c;

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

            add_edge(u,v,d,c);

            add_edge(v,u,d,c);      //双向的路！！！

        }



        //初始化

        memset(mcost, 0, sizeof(mcost));

        fill(d, d+n+1, INF);

        fill(vis, vis+n+1, false);



        int ans=spfa(1);

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

    }



    return 0;

}

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

#include <cstdio>

#include <cstring>

#include <vector>

#include <queue>

using namespace std;

const int INF = 0x3f3f3f3f;

const int MAXN = 10005;

struct Edge

{

    int to, w, cost;

    Edge() {}

    Edge(int a, int b, int c): to(a), w(b), cost(c) {}

    bool operator < (const Edge &r) const

    {

        return w > r.w || w == r.w && cost > r.cost;

    }

};

vector<Edge> G[MAXN];

bool vis[MAXN];

int dist[MAXN];

int cost[MAXN];

int pre[MAXN];

void Dijkstra(int n, int start)

{

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

        vis[i] = 0, dist[i] = cost[i] = INF;

    priority_queue<Edge> que;

    que.push(Edge(start, 0, 0));

    dist[start] = cost[start] = 0;

    pre[start] = start;

    Edge tmp;

    while (!que.empty())

    {

        tmp = que.top();

        que.pop();

        int u = tmp.to;

    //    cout << tmp.to << endl;

        if (vis[u]) continue;

        vis[u] = 1;

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

        {

            int v = G[u][i].to;

            int w = G[u][i].w;

    //        cout << v << " " << w << " " << G[u][i].cost << endl;

    //        cout << dist[v] << " " << cost[v] << endl;

     //       cout << dist[u] << " " << cost[u] << endl;

            if (!vis[v] && dist[v] > dist[u] + w)

            {

                dist[v] = dist[u] + w;

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

      //          cout <<"s1  " << v << " " << dist[v] << " " << cost[v] << endl;

                pre[v] = u;

                que.push(Edge(v, dist[v], cost[v]));

            }

            else if (!vis[v] && dist[v] == dist[u]+w && cost[v] >  G[u][i].cost)

            {

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

         //       cout << "s2  " <<  v << " " << dist[v] << " " << cost[v] << endl;

                pre[v] = u;

                que.push(Edge(v, dist[v], cost[v]));

            }

        }

    }

   // for (int i = 2; i <= n; i++) cout << cost[i] - cost[pre[i]] <<endl;

}

int n, m;

int main()

{

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

    {

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

            G[i].clear();

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

        {

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

            G[u].push_back(Edge(v, d, c));

            G[v].push_back(Edge(u, d, c));

        }

        Dijkstra(n, 1);

        int ans = 0;

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

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

    }

}