// Slower C++ solution:
#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);

    }

}

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

#include <cstdio>

#include <cstring>

#include <queue>

using namespace std;

const int inf =0x3f3f3f3f;

const int MAXN=10005;

struct node

{

    int next, to, d, c;

} G[2000005];

int cur, n;

bool vis[MAXN];

int cost[MAXN];

int dist[MAXN];

int head[MAXN];

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

{

    G[cur].to=v;

    G[cur].c=c;

    G[cur].d=d;

    G[cur].next=head[u];

    head[u]=cur++;

}

queue<int>q;

void spfa(int s)

{



    while(!q.empty()) q.pop();

    memset(vis, false, sizeof(vis));

    fill(cost+1,cost+n+1,inf);

    fill(dist+1,dist+n+1,inf);

    q.push(s);

    dist[s]=0;

    cost[s]=0;

    while(!q.empty())

    {

        int u=q.front();

        q.pop();

        vis[u]=false;

        for(int i=head[u]; ~i; i=G[i].next)

        {

            int v=G[i].to;

            if(dist[v]>dist[u]+G[i].d||(dist[v]==dist[u]+G[i].d&&cost[v]>G[i].c))

            {

                dist[v]=dist[u]+G[i].d;

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

                if(!vis[v])

                {

                    vis[v]=true;

                    q.push(v);

                }

            }

        }

    }

}

int main()

{

    int m;

    int u, v, d, c;

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

    {

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

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

        cur=0;

        while(m--)

        {

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

            add(u, v, d, c);

            add(v, u, d, c);

        }

        spfa(1);

        int ans=0;

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

            ans+=cost[i];

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

    }

    return 0;

}