import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

bool solve() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    if (N == 0) return false;

    alias Edge = Tuple!(int, "to", int, "dist", int, "cost");
    auto G = new Edge[][](N);

    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        G[s[0]-1] ~= Edge(s[1]-1, s[2], s[3]);
        G[s[1]-1] ~= Edge(s[0]-1, s[2], s[3]);
    }

    auto D = new int[](N);
    D[] = 10^^9 + 10;

    auto pq = new BinaryHeap!(Array!Edge, "a.dist == b.dist ? a.cost > b.cost : a.dist > b.dist");
    pq.insert(Edge(0, 0, 0));

    int ans = 0;

    while (!pq.empty) {
        auto n = pq.front.to;
        auto d = pq.front.dist;
        auto c = pq.front.cost;
        pq.removeFront;
        if (D[n] <= d) continue;
        D[n] = d;
        ans += c;
        foreach (e; G[n]) {
            auto m = e.to;
            auto nd = e.dist + d;
            auto nc = e.cost;
            if (D[m] <= nd) continue;
            pq.insert(Edge(m, nd, nc));
        }
    }

    ans.writeln;

    return true;
}

void main() {
    while (solve()) {}
}

