// 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: 4.044017422333548x):
#include <cstdio>

#include <cstring>

#include <algorithm>



using namespace std;



constexpr int maxN = 10005;

constexpr int maxM = 400005;



int N, M;



int adj[maxN], gto[maxM], gnxt[maxM], length[maxM], cost[maxM], e;

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

    gto[e] = v; length[e] = d; cost[e] = c; gnxt[e] = adj[u]; adj[u] = e++;

}



void print_edge(int s) {

    printf("%d:", s);

    for (int e = adj[s]; ~e; e = gnxt[e])

        printf(" %d", gto[e]);

    putchar('\n');

}



int dis[maxN], pre[maxN];

int qu[maxN], qh, qt; bool inq[maxN];

void bellman_ford(int s) {

    memset(dis, 0x3f, sizeof dis); dis[s] = 0;

    for (inq[qu[qh = qt = 0] = s] = 1; qh <= qt; inq[qu[qh++ % N]] = 0)

        for (int u = qu[qh % N], e = adj[u], v = gto[e]; ~e; v = gto[e = gnxt[e]])

            if (dis[v] > dis[u] + length[e]) {

                dis[v] = dis[u] + length[e];

                pre[v] = cost[e];

                if (!inq[v]) inq[qu[++qt % N] = v] = 1;

            } else if (dis[v] == dis[u] + length[e]) {

                pre[v] = min(pre[v], cost[e]);

            }

}



int main() {

    while (~scanf("%d%d", &N, &M) && (N || M)) {

        memset(adj, -1, sizeof adj);

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

        }

        bellman_ford(1);

        long long ans = 0;

        for (int i = 1; i <= N; ++i) ans += pre[i];

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

    }

    return 0;

}