//
// Create by Running Photon on 2015-04-02
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <algorithm>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <set>
#include <vector>
using namespace std;

#define CLR(x) memset(x,0,sizeof x)
#define ll long long
const int inf=0x3f3f3f3f;
const int maxn=5e4+5;
const int MOD=5e5+5;
int cnt, head[maxn], nxt[maxn], pnt[maxn], dist[maxn], cost[maxn];
void add_edge(int u, int v, int ds, int cs){
    dist[cnt] = ds;
    cost[cnt] = cs;
    pnt[cnt] = v;
    nxt[cnt] = head[u];
    head[u] = cnt++;
}
int n, m;
int ans[maxn], dp[maxn];
typedef pair <int, int> sta;
int dijkstra(){
    int ret = 0;
    priority_queue <sta, vector<sta>, greater<sta> >pq;
    memset(dp, 0x3f, sizeof dp);
    memset(ans, 0x3f, sizeof ans);
    pq.push(sta(0, 1)); dp[1] = 0;
    while(!pq.empty()){
        int u = pq.top().second;
        int d = pq.top().first;
        pq.pop();
        if(d > dp[u]) continue;
        for(int i = head[u]; i != -1; i = nxt[i]){
            int v = pnt[i];
            if(dp[v] > dp[u] + dist[i]){
                ans[v] = cost[i];
                dp[v] = dp[u] + dist[i];
                pq.push(sta(dp[v], v));
            }
            else if(dp[v] == dp[u] + dist[i] && ans[v] > cost[i]){
                ans[v] = cost[i];
            }
        }
    }
    for(int i = 2; i <= n; i++) ret += ans[i];
    return ret;
}
int main()
{
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(0);

	while(scanf("%d%d", &n, &m) != EOF && n && m){
        cnt = 0;
        memset(head, -1, sizeof head);
        for(int i = 1; i <= m; i++){
            int u, v, dis, cs;
            scanf("%d%d%d%d", &u, &v, &dis, &cs);
            add_edge(u, v, dis, cs);
            add_edge(v, u, dis, cs);
        }
        printf("%d\n", dijkstra());
	}
	return 0;
}