// Slower C++ solution:
#include <cstdio>

#include <queue>

#include <vector>

#include <algorithm>



using namespace std;

const int INF = 0x3f3f3f3f;



const int maxn = 10240;



struct edge {

	int to, dis, cost;

	edge(int t, int d, int c) : to(t), dis(d), cost(c) {}

};





typedef pair<int, int> p;

priority_queue<p, vector<p>, greater<p> > q;

vector<edge> g[maxn];



int N, M;



void read_in() {

	//scanf("%d%d", &N, &M);

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

		g[i].clear();



	int from, to, dis, cost;

	for(int i = 1; i <= M; i++) {

		scanf("%d%d%d%d", &from, &to, &dis, &cost);

		g[from].push_back(edge(to, dis, cost));

		g[to].push_back(edge(from, dis, cost));

	}

}



int solve() {

	q.push(p(0, 1));



	const int INF = 0x7777777;

	int d[maxn];



	for(int i = 2; i <= N; i++) 

		d[i] = INF;

	d[1] = 0;



	while( !q.empty() ) {

		p t = q.top();

		q.pop();



		int to = t.second, dis = t.first;

        if(d[to] < dis) continue;

		for(unsigned int i = 0; i < g[to].size(); i++) {

			edge To = g[to][i];

			if(d[To.to] > d[to] + To.dis)

				d[To.to] = d[to] + To.dis,

				q.push(p(d[To.to], To.to));

		}

	}

	//show(d);

    int ans = 0;



    for(int i = 2; i <= N; i++) {

        int tmp = INF;



        for(int j = 0; j < g[i].size(); j++) {

            edge e = g[i][j];

            if(d[e.to] + e.dis == d[i] and e.cost < tmp)

                tmp = e.cost;

        }

        ans += tmp;

    }



    return ans;

}



int main() {

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

		read_in();

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

	}

	return 0;

}




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

#include <cstring>

#include <queue>

using namespace std;

const int INF = 0x3f3f3f3f;

struct node

{

    int to, w, c, next;

} edge[50005];

int head[10005], ip, cost[10005], dis[10005], n, m;

bool vis[10005];

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

{

    edge[ip].to = v;

    edge[ip].w = d;

    edge[ip].c = c;

    edge[ip].next = head[u];

    head[u] = ip++;

}

void spfa(int s)

{

    queue<int> q;

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

        cost[i] = dis[i] = INF;

    memset(vis, 0, sizeof(vis));

    dis[s] = 0;

    cost[s] = 0;

    vis[s] = 1;

    q.push(s);

    while (!q.empty())

    {

        int u = q.front();

        q.pop();

        vis[u] = 0;

        for(int i = head[u];i != -1;i = edge[i].next)

        {

            int to = edge[i].to;

            int w = edge[i].w;

            if(dis[to] > dis[u] + w||(dis[to] == dis[u]+w&&cost[to] > edge[i].c))

            {

                dis[to] = dis[u] + w;

                cost[to] = edge[i].c;

                if(!vis[to])

                {

                    q.push(to);

                    vis[to] = 1;

                }

            }

        }

    }

}

int main()

{

    while (scanf("%d %d", &n, &m) != EOF)

    {

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

            break;

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

        ip = 0;

        for (int i = 0; i < m; i++)

        {

            int u, v, d, c;

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

            addedge(u, v, d, c);

            addedge(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;

}