using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

class AOJ
{
    static void Main(string[] args)
    {
        int INF = 1 << 28;
        while (true)
        {
            string[] tmp = Console.ReadLine().Split(' ');
            int n = int.Parse(tmp[0]);
            int m = int.Parse(tmp[1]);
            if ((n | m) == 0) break;
            ArrayList[] es = new ArrayList[n + 1];
            for (int i = 1; i <= n; i++)
            {
                es[i] = new ArrayList();
            }
            for (int i = 0; i < m; i++)
            {
                string[] data = Console.ReadLine().Split(' ');
                int u = int.Parse(data[0]);
                int v = int.Parse(data[1]);
                int d = int.Parse(data[2]);
                int c = int.Parse(data[3]);
                es[u].Add(new Edge(v, d, c));
                es[v].Add(new Edge(u, d, c));
            }
            /* dis[i] := the distance between 1-th and i-th */
            int[] dis = new int[n + 1];
            dis = Enumerable.Repeat(INF, n + 1).ToArray();
            dis[1] = 0;
            PriorityQueue<Pair> q = new PriorityQueue<Pair>(compare);
            q.Add(new Pair(0, 1));
            while (!q.isEmpty())
            {
                Pair p = q.Poll();
                int v = p.v;
                if (dis[v] < p.d)
                    continue;
                foreach (Edge e in es[v])
                {
                    if (dis[e.to] > dis[v] + e.d)
                    {
                        dis[e.to] = dis[v] + e.d;
                        q.Add(new Pair(dis[e.to], e.to));
                    }
                }
            }
            int ans = 0;
            for (int i = 2; i <= n; i++)
            {
                int min = INF;
                foreach (Edge e in es[i])
                {
                    int v = e.to;
                    int d = e.d;
                    int c = e.c;
                    if (dis[v] + d == dis[i])
                    {
                        min = Math.Min(min, c);

                    }
                } 
                    ans += min;
            }
            Console.WriteLine(ans);
        }
    }
    static int compare(Pair a, Pair b)
    {
        return a.d - b.d;
    }
}

public class PriorityQueue<T>
{
    List<T> list = new List<T>();
    IComparer<T> comp = Comparer<T>.Default;
    class Comparer : IComparer<T>
    {
        Comparison<T> comparison;
        public Comparer(Comparison<T> comparison) { this.comparison = comparison; }
        public int Compare(T x, T y) { return comparison(x, y); }
    }
    public PriorityQueue() { }
    public PriorityQueue(Comparison<T> comp) { this.comp = new Comparer(comp); }
    public void Add(T item) { int i = list.BinarySearch(item, comp); list.Insert(i < 0 ? ~i : i, item); }
    public T Poll() { T r = list[0]; list.RemoveAt(0); return r; }
    public T Peek() { return list[0]; }
    public int Count { get { return list.Count; } }
    public bool isEmpty() { return list.Count == 0; }
    public T this[int i] { get { return list[i]; } set { list[i] = value; } }
}
class Pair
{
    public int v;
    public int d;
    public Pair(int d, int v)
    {
        this.v = v;
        this.d = d;
    }
}

class Edge
{
    public int to;
    public int d;
    public int c;

    public Edge(int to, int dis, int c)
    {
        this.to = to;
        this.d = dis;
        this.c = c;
    }

    public String toString()
    {
        return "to: " + to + " dist: " + d;
    }
}

Measured memory_bytes: 10488