#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

//li chao tree by ei1333. It's public available.
// https://ei1333.github.io/luzhiled/snippets/structure/li-chao-tree.html
/*
template< typename T >
struct LiChaoTree {
    struct Line {
        T a, b;

        Line(T a, T b) : a(a), b(b) {}

        inline T get(T x) const { return a * x + b; }

        inline bool over(const Line& b, const T& x) const {
            return get(x) < b.get(x);
        }
    };

    vector< T > xs;
    vector< Line > seg;
    int sz;

    LiChaoTree(const vector< T >& x, T INF) : xs(x) {
        sz = 1;
        while (sz < xs.size()) sz <<= 1;
        while (xs.size() < sz) xs.push_back(xs.back() + 1);
        seg.assign(2 * sz - 1, Line(0, INF));
    }

    void update(Line& x, int k, int l, int r) {
        int mid = (l + r) >> 1;
        auto latte = x.over(seg[k], xs[l]), malta = x.over(seg[k], xs[mid]);
        if (malta) swap(seg[k], x);
        if (l + 1 >= r) return;
        else if (latte != malta) update(x, 2 * k + 1, l, mid);
        else update(x, 2 * k + 2, mid, r);
    }

    void update(T a, T b) { // ax+b
        Line l(a, b);
        update(l, 0, 0, sz);
    }

    T query(int k) { // xs[k]
        const T x = xs[k];
        k += sz - 1;
        T ret = seg[k].get(x);
        while (k > 0) {
            k = (k - 1) >> 1;
            ret = min(ret, seg[k].get(x));
        }
        return ret;
    }
};

#define int long long
void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> landmarks;
    vector<vector<int>> costs;
    REP(i, n) {
        vector<int> tmp;
        REP(q, m) {
            int b;
            cin >> b;
            b = xor128() % 10000000;
            tmp.push_back(b);
        }
        landmarks.push_back(tmp);
    }
    REP(i, n) {

        vector<int> tmp;
        {
            REP(q, m) {
                int b;
                cin >> b;
                b = xor128() % 100000000;
                tmp.push_back(b);
            }
        }
        costs.push_back(tmp);
    }
    vector<LiChaoTree<int>> yoko; // size should be m
    REP(i, n) {
        vector<int> hoge(m);
        REP(q, m) {
            hoge[q] = q;
        }
        LiChaoTree<int> now(hoge, 1e18);//size should be n
        yoko.push_back(now);
    }
    vector<vector<int>> dp = landmarks;
    for (int q = 0; q < m; ++q) {
        vector<int> hoge(n);
        REP(i, n) {
            hoge[i] = i;
        }
        LiChaoTree<int> now(hoge, 1e18);//size should be n

        for (int i = 0; i < n; ++i) {
            int now_min = costs[0][0] * (i + q);
            if (q < 0) {
                int geko = yoko[i].query(q);
                now_min = min(now_min, geko);
            }
            if (i != 0) {
                int geko = now.query(i);
                now_min = min(now_min, geko);
            }
            dp[i][q] = now_min;
            yoko[i].update(costs[i][q], landmarks[i][q] + dp[i][q] - q * costs[i][q]);
            now.update(costs[i][q], landmarks[i][q] + dp[i][q] - i * costs[i][q]);
        }
    }

    cout << dp[n - 1][m - 1] << endl;
}
*/
#define int ll
vector<pair<int, int>> vertexs[200000];
int dist[200000];
int cnt[200000];
void solve() {
    while (true) {
        int n, m;
        cin >> n >> m;
        if (n == 0) return;
        REP(i, n + 1) {
            dist[i] = 1e9;
            vertexs[i].clear();
            cnt[i] = 0;
        }
        vector<tuple<int, int, int, int>> edges;
        REP(i, m) {
            int a, b, c, d;
            cin >> a >> b >> c >> d;
            a--; b--;
            edges.push_back(make_tuple(d, a, b, c));
            vertexs[a].push_back(make_pair(b, c));
            vertexs[b].push_back(mp(a, c));
        }
        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> next;
        REP(i, n) {
            dist[i] = 1e9;
        }
        dist[0] = 0;
        next.push(mp(0, 0));
        while (next.empty() == false) {
            pair<int, int> now = next.top();
            next.pop();
            if (dist[now.second] != now.first) continue;
            for (auto x : vertexs[now.second]) {
                if (dist[x.first] > x.second + now.first) {
                    dist[x.first] = x.second + now.first;
                    next.push(mp(dist[x.first], x.first));
                }
            }
        }
        sort(ALL(edges));
        cnt[0] = 1;
        int ans = 0;
        for (int i = 0; i < edges.size(); ++i) {
            REP(q, 2) {
                if (dist[get<1>(edges[i])] + get<3>(edges[i]) == dist[get<2>(edges[i])]) {
                    if (cnt[get<2>(edges[i])] == 0) {
                        cnt[get<2>(edges[i])] = 1;
                        ans += get<0>(edges[i]);
                    }
                }
                swap(get<1>(edges[i]), get<2>(edges[i]));
            }
        }
        cout << ans << endl;
    }
}
#undef int
int main() {
    init();
    solve();
}


Measured memory_bytes: 11488